getting attributes value from XML using XSLT

Discussion in 'XML' started by Venkat, Mar 23, 2005.

  1. Venkat

    Venkat Guest

    Hi There,

    Can you please help me with this XSLT ? I am trying to extract
    erp,catalog and description,price from the following xml , each record
    in a single row.

    Sample XSL which I am trying to use
    =====================================
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:java="http://xml.apache.org/xslt/java"
    exclude-result-prefixes="java"
    version="1.0">
    <xsl:eek:utput method="text"/>
    <xsl:template match="//group">
    <xsl:for-each select="product">
    <xsl:value-of select="price"/>
    <xsl:value-of select="description"/>

    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>


    Sample XML
    ========
    <group>
    <product erp="111-V1111" catalog="X43343IHG">
    <description> Test Description 1</description>
    <price>250.00</price>
    </product>
    <product erp="222-V2222" catalog="X433333N">
    <description>Test Description 2</description>
    <price>200.00</price>
    </product>
    <product erp="333-V3332" catalog="X43534347B">
    <description>Test Description 3</description>
    <price>200.00</price>
    </product>
    </group>


    Thanks in advance.
    Venkat
    Venkat, Mar 23, 2005
    #1
    1. Advertising

  2. Venkat

    Romin Guest

    Use the @attribute-name to get the value of the attribute for the
    current context.

    Inside your <xsl:for-each select="product"> block, use the following:

    <xsl:value-of select="@erp"/>
    <xsl:value-of select="@catalog"/>

    to extract the value of the erp and catalog attributes.

    Romin
    Romin, Mar 23, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    2
    Views:
    817
    Wolfgang
    Apr 9, 2004
  2. Wolfgang
    Replies:
    0
    Views:
    409
    Wolfgang
    Apr 6, 2004
  3. Jordan Willms
    Replies:
    2
    Views:
    820
    Richard Tobin
    Nov 9, 2004
  4. =?UTF-8?b?5byg6Z+h5q2m?=
    Replies:
    3
    Views:
    697
    DeepthiShri
    Oct 23, 2006
  5. =?iso-8859-1?q?Christian_R=FChl?=

    Extend XML file attributes using XSLT

    =?iso-8859-1?q?Christian_R=FChl?=, Nov 9, 2007, in forum: XML
    Replies:
    13
    Views:
    828
    Christian Rühl
    Nov 26, 2007
Loading...

Share This Page