Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > getting attributes value from XML using XSLT

Reply
Thread Tools

getting attributes value from XML using XSLT

 
 
Venkat
Guest
Posts: n/a
 
      03-23-2005
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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="java"
version="1.0">
<xslutput 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

 
Reply With Quote
 
 
 
 
Romin
Guest
Posts: n/a
 
      03-23-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extend XML file attributes using XSLT =?iso-8859-1?q?Christian_R=FChl?= XML 13 11-26-2007 03:37 PM
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
xslt: how to use value from xml data as an attribute value in output html? =?UTF-8?b?5byg6Z+h5q2m?= XML 3 10-23-2006 02:31 PM
XSLT: Confusion over adding attributes with xml:element and xml:attribute Jordan Willms XML 2 11-09-2004 12:25 AM
XML file-- XSLT transformation problem with attributes of root element Wolfgang XML 2 04-09-2004 01:20 AM



Advertisments