-
May 3rd, 2011, 09:36 AM
#1
Finding Element Without Knowing Path
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
-
May 3rd, 2011, 09:37 AM
#2
Re: Finding Element Without Knowing Path
lame, it took out my spacing!
-
May 3rd, 2011, 09:47 AM
#3
Re: Finding Element Without Knowing Path
nevermind, I figured it out:
<xsl:for-each select=".//description">
.
.
.
</xsl:for-each>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|