CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2011
    Posts
    6

    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

  2. #2
    Join Date
    May 2011
    Posts
    6

    Re: Finding Element Without Knowing Path

    lame, it took out my spacing!

  3. #3
    Join Date
    May 2011
    Posts
    6

    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
  •  





Click Here to Expand Forum to Full Width

Featured