views:

27

answers:

2

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
                        </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

A: 

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>
ZeissS
A: 

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
Dimitre Novatchev
Fast reply thanks
Mark
Note that the iwwr is an alias for the full namespace in this example.
Mark Schultheiss
@Mark-Schultheiss: Is this comment for me and if yes, what is its meaning? A namespace prefix is a namespace prefix. By definition it is bound to a namespace-uri. My answer demonstrates how to use a namespace-prefix bound to a specific namespace in order to make an XPath expression, containing names of elements belonging to that namespace, more readable.
Dimitre Novatchev