Extract nested data from XML via XSLT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SandIsland
    New Member
    • Nov 2007
    • 3

    Extract nested data from XML via XSLT

    I am trying to extract just a portion of data from an XML data source:

    <Row>
    <Col Name="Col0">123 456<CellColour> 36</CellColour>
    <FontColour>1 </FontColour>
    <Bottom>1</Bottom>
    <Bold>False</Bold>
    <Italic>False </Italic>
    <TextDirection> 0</TextDirection>
    </Col>
    </Row>

    When I extract the Col field I get "1234563612111F alsexlCenterxlB ottomFalse00Fal se" using " <xsl:value-of select="Col"/>".


    I just want the first portion of data "123456". I do not need any of the html tags or html data.

    Any suggestions? Any direction on this would be greatly appreciated.

    Thanks.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    <xsl:value-of select="Col/text()"/>
    or
    <xsl:value-of select="Col/text()[1]"/>

    Comment

    • SandIsland
      New Member
      • Nov 2007
      • 3

      #3
      That worked great!!. Thanks

      One more question to extend your reply..

      Each set is named "<Col Name="Col0">123 456". How do I reference them by name?

      ie.
      Col Name="Col0">123 456
      Col Name="Col1">456 789
      Col Name="Col2">678 912
      Col Name="Col3">234 565

      Meaning each has its own name Col0, Col1, Col2, etc.

      When using Col/text() it pulls only the first Col0 as that is the tag of the data set. I already have a loop setup which now grabs the first Col/text() in each set. I how do I pull them by name?

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Not entirely sure what you want.
        Either <xsl:value-of select="Col[@name = 'Col0']/text()"/>

        Or
        Code:
        <xsl:for-each select="Col">
          <xsl:value-of select="@name"/>:<xsl:value-of select="text()"/>
        </xsl:for-each>

        Comment

        • SandIsland
          New Member
          • Nov 2007
          • 3

          #5
          Perfect!!

          That was exactly what I needed.

          Thanks again!!

          Comment

          Working...