我有以下XML:
<?xml version="1.0" encoding="UTF-8"?>
<gbXML version="0.37" useSIUnitsForResults="true" volumeUnit="CubicMeters" areaUnit="SquareMeters" lengthUnit="Meters" temperatureUnit="C" xmlns="http://www.gbxml.org/schema" xsi:schemaLocation="http://www.gbxml.org/schema xsi.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Campus id="cmps-1">
<Location>
<Name>Trois-Rivieres, PQ Canada</Name>
<Latitude>46.210000</Latitude>
<Longitude>-72.350000</Longitude>
</Location>
</Campus>
</gbXML>
我想选择“纬度”值。 我正在使用下面没有返回任何内容的XPath表达式:
<p><code><xsl:value-of select="gbXML/Campus/Location/Latitude"/></code></p>
我是XPath的新手,如果有人可以帮我解决这个问题,我将非常感激。
答案 0 :(得分:0)
您有一个默认的命名空间xmlns="http://www.gbxml.org/schema"
。
在您的XSLT中,只需添加另一个名称空间,例如xmlns:text="xmlns="http://www.gbxml.org/schema"
(您正在创建默认名称空间的快捷方式)。
另外添加exclude-result-prefixes="text"
以省略输出中的text
前缀。
然后,改变:
<p><code><xsl:value-of select="gbXML/Campus/Location/Latitude"/></code></p>
到
<p><code><xsl:value-of select="text:gbXML/text:Campus/text:Location/text:Latitude"/></code></p>
答案 1 :(得分:0)
您缺少xpath中的命名空间声明。在样式表中声明名称空间,然后在xpath中使用前缀:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:gb="http://www.gbxml.org/schema">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<p><code><xsl:value-of select="gb:gbXML/gb:Campus/gb:Location/gb:Latitude"/></code></p>
</xsl:template>
</xsl:stylesheet>