For the following 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
<开发者_Python百科/field>
</metadata>
</document>
</assets>
</results>
</Result>
</Data>
How would I select the path attribute from the document element? My current xslt is:
<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>
If I remove the xmlns, xmlns:xsi and xsi:schemaLocation from the results element of the xml the xslt will work. So obviously I don't understand the namespace stuff and would greatly appreciate some insight. Thanks
This transformation:
<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>
when applied to the provided XML document, produces the value of the path
attribute as required:
templatedata/www/location/data/Belton
You have to add the namespaces to your xpath, too:
<xsl:apply-templates xmlns:iwrr="http://www.interwoven.com/schema/iwrr" select="Properties/Data/Result/iwrr:results/iwr:assets/iwr:document"></xsl:apply-templates>
精彩评论