chongzilla
May 3rd, 2011, 09:36 AM
Hi,
This may be ridiculously simple. I've been working with the same schema for years and it's fairly flat, but I'm on a new project where simple attributes are inherited in the schema all over the place. If I want to just get the description for each individual object without knowing the full path to it, how would I do that?
Example xml:
<test>
<activity>
<individual>
<name>Test1</name>
<description>this is description</description>
</individual>
</activity>
<activity>
<thing>
<action>
<name>Test2</name>
<description>this is description2</description>
</action>
</thing>
</activity>
<activity>
<test>
<individual>
<thing>
<name>Test3</name>
<description>this is description3</description>
</thing>
</individual>
</test>
</activity>
</test>
I tried:
<xsl:template match="test">
<xsl:element name="root">
<xsl:for-each select="./activity">
<xsl:element name="object">
<xsl:for-each select="//name[1]">
<title><xsl:value-of select="."/></title>
</xsl:for-each>
<xsl:for-each select="//description[1]">
<descript><xsl:value-of select="."/></descript>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
But I got every description...
Any help would be appreciated.
Thanks,
Stan
This may be ridiculously simple. I've been working with the same schema for years and it's fairly flat, but I'm on a new project where simple attributes are inherited in the schema all over the place. If I want to just get the description for each individual object without knowing the full path to it, how would I do that?
Example xml:
<test>
<activity>
<individual>
<name>Test1</name>
<description>this is description</description>
</individual>
</activity>
<activity>
<thing>
<action>
<name>Test2</name>
<description>this is description2</description>
</action>
</thing>
</activity>
<activity>
<test>
<individual>
<thing>
<name>Test3</name>
<description>this is description3</description>
</thing>
</individual>
</test>
</activity>
</test>
I tried:
<xsl:template match="test">
<xsl:element name="root">
<xsl:for-each select="./activity">
<xsl:element name="object">
<xsl:for-each select="//name[1]">
<title><xsl:value-of select="."/></title>
</xsl:for-each>
<xsl:for-each select="//description[1]">
<descript><xsl:value-of select="."/></descript>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
But I got every description...
Any help would be appreciated.
Thanks,
Stan