Xml 使用XSLT在网站中包含天气报告
我想在我的网站上包括天气预报 我想包括的具体元素位于:Xml 使用XSLT在网站中包含天气报告,xml,xslt,Xml,Xslt,我想在我的网站上包括天气预报 我想包括的具体元素位于: report/data/location/block 其中块包含: <field_id>Verwachting</field_id> Verwachting 如何使用简单的XSL转换实现这一点 更新: 我进行了以下XSL转换,但没有结果: <xsl:variable name="weerknmi" select="document('ftp://ftp.knmi.nl/pub_weerberichten/
report/data/location/block
其中块包含:
<field_id>Verwachting</field_id>
Verwachting
如何使用简单的XSL转换实现这一点
更新:
我进行了以下XSL转换,但没有结果:
<xsl:variable name="weerknmi" select="document('ftp://ftp.knmi.nl/pub_weerberichten/basisverwachting.xml')/report/data/location"/>
<xsl:value-of select="$weerknmi/block[field_id = 'Verwachting']/field_content"/>
一个简单的XPath表达式可以做到这一点:
report/data/location/block[field\u id='Verwachting']/field\u content
如果要在XSLT中使用此功能,可以执行以下操作:
我的语法可能有点错误,我不经常使用document()
,现在也不容易检查,但你明白了。使用
report/data/location/block[field_id='Verwachting']/field_content
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vDoc" select=
"document('ftp://ftp.knmi.nl/pub_weerberichten/basisverwachting.xml')"/>
<xsl:template match="/">
<xsl:apply-templates select="$vDoc" mode="doc"/>
</xsl:template>
<xsl:template match="/" mode="doc">
<xsl:value-of select=
"report/data/location/block[field_id='Verwachting']/field_content"/>
</xsl:template>
</xsl:stylesheet>
这里是一个完整且非常简短的XSLT转换:
report/data/location/block[field_id='Verwachting']/field_content
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vDoc" select=
"document('ftp://ftp.knmi.nl/pub_weerberichten/basisverwachting.xml')"/>
<xsl:template match="/">
<xsl:apply-templates select="$vDoc" mode="doc"/>
</xsl:template>
<xsl:template match="/" mode="doc">
<xsl:value-of select=
"report/data/location/block[field_id='Verwachting']/field_content"/>
</xsl:template>
</xsl:stylesheet>
当应用于任何文档(未使用)时,转换将动态获取位于ar的XML文档,对其进行处理,并生成所需的结果:
report/data/location/block[field_id='Verwachting']/field_content
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vDoc" select=
"document('ftp://ftp.knmi.nl/pub_weerberichten/basisverwachting.xml')"/>
<xsl:template match="/">
<xsl:apply-templates select="$vDoc" mode="doc"/>
</xsl:template>
<xsl:template match="/" mode="doc">
<xsl:value-of select=
"report/data/location/block[field_id='Verwachting']/field_content"/>
</xsl:template>
</xsl:stylesheet>
弗瑞吉·维尔·贝沃金(Vrij veel bewolking en vooral)在摩特雷根(motregen)的第二次摄政中担任总统。在这片土地上,他长得太高了。在苏伊多斯滕省,14岁的温哥华中学的学生在19年级就毕业了。德祖伊德韦斯特利克的风正吹拂着弗拉赫蒂格。安·德·库斯特是哈德郡的德温·克拉赫蒂格,6比7
Komende nacht是vrij veel bewolking在noorden和nog lichte regen的中间地带相遇的。最低温度为11摄氏度。德苏伊德韦斯特利克风力发电厂位于克拉赫特3号。阿恩·德库斯特(Aan de kust)是5岁的弗拉赫蒂格(vrij krachtig)
Morgen overdag breekt op steeds meer plaatsen de zon door是一款整体下垂的服装。在诺德威斯特利克库斯特格比德的16岁学生中,苏伊多斯滕的中等温度为23年级。德祖维斯特利克风力发电厂位于克莱希蒂格,克莱希特5年中的第4年,克莱希特7年中的第6年。’s避免neemt de wind af.(Bron:KNMI)在字段内容修复语法错误后删除方括号,但是转换没有结果。我更新了问题Woops,那肯定是个打字错误!我已经修好了。问得好,+1。查看我的答案,了解一个完整、简短且简单的转换,您只需运行该转换即可生成所需的结果。:)我尝试在一个空XML文件上使用这个XSL转换,但结果是空的。没有解析错误。我的目标是Firefox4.0.1。您确定Xpath查询是正确的吗?