getting attributes value from XML using XSLT

V

Venkat

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
 
R

Romin

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top