 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 28th, 2008, 10:59 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to read Array using XSL
Hello All,
Following is a xml code snippet
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="email-template.xslt"?>
<root>
<UserName>CK</UserName>
<Password>RB@QK-APAJO</Password>
<ArrayOfOrderItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderItem ProductId="" SKU="ACD0001" Title="Aircraft for Dummies" DownloadUrl="http://www.fileopen.com/" Quantity="1" UnitPrice="64.36" />
<OrderItem ProductId="" SKU="ACD0002" Title="AC Test Manual 1" DownloadUrl="http://www.fileopen.com/" Quantity="1" UnitPrice="100.00" />
</ArrayOfOrderItem>
</root>
My question was I had to read individual values for the node OrderItem, like ProductId , SKU, Title, DownloadURL etc in a "xsl". How to use xsl:select? or is there anything else that is to be used?
Thank you in advance.
|
|

May 28th, 2008, 11:07 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You've shown us your input but you haven't given any information about what output you are trying to produce. You've obviously attempted to write some code but we can't see it so we can't tell you what's wrong with it.
There is no such thing as xsl:select.
Perhaps you need to start by reading a good book about XSLT.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 28th, 2008, 11:08 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
The 'OrderItem' elements have attributes named 'ProductId', 'SKU', 'Title' etc.
You can access an attribute in XPath as e.g. @attributeName e.g. @ProductId or you can use @* to select all attributes of the context node:
Code:
<xsl:for-each select="/root/ArrayOfOrderItem/OrderItem">
<xsl:for-each select="@*">
<xsl:value-of select="concat('attribute named ', local-name(), ' has value ', .)"/>
</xsl:for-each>
</xsl:for-each>
--
Martin Honnen
Microsoft MVP - XML
|
|

May 28th, 2008, 11:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Hi
I'm not sure what you are referring to when you mention xsl:select - there is no such XSLT instruction.
XSLT uses XPATH to identify elements in its input documents, so you might refer to the UserName element as "/root/UserName"
However without knowing what your output should look like, and what you have so far in your email-template.xslt it would be hard to say.
/- Sam Judson : Wrox Technical Editor -/
|
|

May 28th, 2008, 11:23 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Thanks for the reply and suggestion. I apologise for saying xsl:select. What I meant was xsl:value-of select. The code I pasted in the first post was an xml for which I am writing a stylesheet. My problem is reading the individual values under the node OrderItem. I don't know how to read the values of ProductId, SKU, DownloadUrl etc. Can anyone please give a sample code of how to write it.
Thanks in advance.
|
|

May 28th, 2008, 11:34 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
As I said, 'ProductId', 'SKU' and so on are attributes of the 'OrderItem' elements.
I have already posted code that shows how to access and output all attributes of the OrderItem elements. It is the bare code to do that, you will need to add some formatting depending on whether you want to output HTML or XML or plain text.
--
Martin Honnen
Microsoft MVP - XML
|
|

May 28th, 2008, 11:39 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
My guess would be that if you're having difficulties here then it's probably because you haven't understood the concept of the context node. But I can't help you correct your code without seeing it.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

May 28th, 2008, 12:29 PM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Martin Honnen
As I said, 'ProductId', 'SKU' and so on are attributes of the 'OrderItem' elements.
I have already posted code that shows how to access and output all attributes of the OrderItem elements. It is the bare code to do that, you will need to add some formatting depending on whether you want to output HTML or XML or plain text.
--
Martin Honnen
Microsoft MVP - XML
|
Thank you for your reply Martin. That helped to solve the problem.
|
|
 |