对于下面的XML
<Properties ComponentID="1272040480745" Admin="true">
<Datum ID="P01" Type="File" Name="CSS To Use">style.css</Datum>
<Data>
<External></External>
<Result>
<results xmlns="http://www.interwoven.com/schema/iwrr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.interwoven.com/schema/iwrr iwrr.xsd" total="1" included="1" start="0" status="200">
<assets>
<document id="019c7c763e5ae286c7d566ff883f8199" uri="/document/id/019c7c763e5ae286c7d566ff883f8199" context="cb478aef64c6415b390e241885fd1346" path="templatedata/www/location/data/Belton">
<metadata>
<field name="TeamSite/Metadata/locationRegion">
Central
</field>
</metadata>
</document>
</assets>
</results>
</Result>
</Data>
如何从文档元素中选择路径属性?我目前的xslt是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<div>
<xsl:apply-templates select="Properties/Data/Result/results/assets/document"></xsl:apply-templates>
<xsl:text>HELLO THERE!</xsl:text>
</div>
</xsl:template>
<xsl:template match="document">
<xsl:value-of select="@path"></xsl:value-of>
</xsl:template>
</xsl:stylesheet> 如果我从xml的results元素中删除xmlns、xmlns:xsi和xsi:schemaLocation,xslt就会正常工作。因此,很明显,我不了解名称空间的东西,并非常感谢一些见解。谢谢
发布于 2010-06-25 05:28:04
此转换
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:iwwr="http://www.interwoven.com/schema/iwrr"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="/*/*/*/iwwr:results/*/iwwr:document/@path"/>
</xsl:template>
</xsl:stylesheet>当将应用于所提供的XML文档时,会将 path 属性的值生成为必需的。
templatedata/www/location/data/Belton发布于 2010-06-25 05:17:31
您还必须将名称空间添加到xpath中:
<xsl:apply-templates xmlns:iwrr="http://www.interwoven.com/schema/iwrr" select="Properties/Data/Result/iwrr:results/iwr:assets/iwr:document"></xsl:apply-templates>https://stackoverflow.com/questions/3113914
复制相似问题