Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old February 13th, 2006, 05:48 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Nodes ....'For Each' problem.

Hi,

I have a problem trying to return nodes in sequential order from the following example. The 'for each' statement that I'm using only returns the 1st node (5 times in this example). I've divided the code into 2 parts (the XML & the XSL) and this example only has the 1st node used in the output file:

[u]XML</u>
<ShippingInstructions ShippingType="Delivery">
<ShippingDate DateTimeType="Earliest Delivery">20060214 07:00</ShippingDate>
<ShippingDate DateTimeType="Dispatch Date">20060214</ShippingDate>
<ShippingDate DateTimeType="Earliest Available">20060214 07:00</ShippingDate>
<ShippingDate DateTimeType="Latest Available">20060214 07:00</ShippingDate>
<ShippingDate DateTimeType="Latest Delivery">20060214 17:00</ShippingDate>
<Description>D/O 6263/1+6198/1+6902/1 38484</Description>
</ShippingInstructions>

[u]XSL</u>
<xsl:when test="@ShippingType='Delivery'">
....
<xsl:call-template name="ha"/>
</xsl:when>

<xsl:template name="ha">
<xsl:attribute name="ShippingType"><xsl:text>Delivery</xsl:text></xsl:attribute>
<xsl:for-each select="ShippingDate">
<xsl:element name="ShippingDate">
<xsl:variable name="EarlDel" select="../ShippingDate"/>
<xsl:attribute name="DateTimeType">Earliest Delivery</xsl:attribute>
<xsl:value-of select="$EarlDel"/>
</xsl:element>
</xsl:for-each>
</xsl:template>

[u]Question 1</u>
I'm sure it's the select statement is my problem but please can anyone help?

[u]Question 2</u>
Also, each time I loop through the 'for each' statement I need to populate the output with the next node. How do I do this?

Please understand, I'm fairly new to this.

Thanks,


Neal

A Northern Soul
__________________
Neal

A Northern Soul
 
Old February 13th, 2006, 07:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm a bit puzzled by your problem because your code seems to be written very carefully to select the first Shipping Date. Let's walk through it:

<xsl:for-each select="ShippingDate">
-- for each ShippingDate in the input

<xsl:element name="ShippingDate">
-- create a ShippingDate in the output

<xsl:variable name="EarlDel" select="../ShippingDate"/>
-- create a variable whose value is the set of all ShippingDate elements owned by the parent of this ShippingDate

<xsl:attribute name="DateTimeType">Earliest Delivery</xsl:attribute>
-- create an attribute whose name is "DateTimeType" and whose value is the string "Earliest Delivery"

<xsl:value-of select="$EarlDel"/>
-- output the string-value of the first node in the set $EarlDel, that is, the first child of the parent ShippingInstructions.

If you want to output the current node, just do <xsl:value-of select="."/> in the usual way, but then all the stuff about labelling it as the "earliest delivery" is nonsense.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 13th, 2006, 07:49 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Yes, I know it's perhaps my unclear explanation in the aforementioned code. Sorry!

<xsl:variable name="EarlDel" select="../ShippingDate"/>
-- create a variable whose value is the set of all ShippingDate elements owned by the parent of this ShippingDate

I do not want to return all shippingDate elements 'in one go' as you correctly stated.

So, how do I populate each ShippingDate element (DateTimeType) into 'EarlDel' individually (one at a time)? I need to evaluate each ShippingDate element.


Neal

A Northern Soul
 
Old February 13th, 2006, 08:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You do it the way I said, using <xsl:value-of select="."/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to value in b/n nodes Swetha XSLT 1 May 20th, 2008 12:20 PM
problem accessing nodes using document() and id() siris phi XSLT 3 April 12th, 2007 11:05 PM
Problem Copying Nodes tclotworthy XSLT 14 February 13th, 2007 01:13 PM
Problem copying XML nodes francislang XSLT 9 October 21st, 2005 10:37 AM
reorder nodes problem pompluck XSLT 4 November 5th, 2003 09:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.