Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 14th, 2006, 06:03 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy one node to another in XSL

Hi i´m sorry if the subject is not very correct

Here my XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Order xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <OrderReferences>
    <BuyersOrderNumber>32761</BuyersOrderNumber>
  </OrderReferences>
  <Supplier>
    <SupplierReferences>
      <TaxNumber>500336512</TaxNumber>
    </SupplierReferences>
  </Supplier>
  <OrderLine>
    <LineNumber>1</LineNumber>
    <Product>
      <TradeUnitCode>8645028</TradeUnitCode>
    </Product>
    <Quantity>
      <Amount UOMCode="PCE">5.0000</Amount>
    </Quantity>
  </OrderLine>
  <OrderLine>
    <LineNumber>2</LineNumber>
    <Product>
      <TradeUnitCode>8645022</TradeUnitCode>
    </Product>
    <Quantity>
      <Amount UOMCode="PCE">2.0000</Amount>
    </Quantity>
  </OrderLine>
</Order>

My XSL:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version = "1.0"
    xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="Order"><xsl:text/>
<xsl:value-of select="normalize-space(./OrderReferences)"/><xsl:text/>

<xsl:for-each select="./OrderLine">

<xsl:value-of select="normalize-space(LineNumber)"/><xsl:text/>
<xsl:value-of select="normalize-space(Product)"/><xsl:text/>
<xsl:value-of select="normalize-space(Quantity)"/>#013;<xsl:text/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

And my OUTPUT is:

32761186450285.0000
286450222.0000

What i want is that the node (OrderReferences - i think that is a node) is copy for all lines below.
It should be like this:

32761186450285.0000
32761286450222.0000

I´m sorry if the question is silly but i´m not very good with xsl.
Thank you very much.

Reply With Quote
  #2 (permalink)  
Old September 14th, 2006, 06:13 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Put the value in a variable and use it repeatedly withing the for-each loop:

<xsl:template match="Order"><xsl:text/>
<xsl:variable name="ref" select="normalize-space(./OrderReferences)"/><xsl:text/>

<xsl:for-each select="./OrderLine">
<xsl:value-of select="$ref"/>
<xsl:value-of select="normalize-space(LineNumber)"/><xsl:text/>
<xsl:value-of select="normalize-space(Product)"/><xsl:text/>
<xsl:value-of select="normalize-space(Quantity)"/>#013;<xsl:text/>
</xsl:for-each>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old September 14th, 2006, 06:20 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks mhkay you save my life.

Reply With Quote
  #4 (permalink)  
Old September 14th, 2006, 09:01 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version = "1.0"
    xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="Order"><xsl:text/>
<xsl:variable name="ref" select='format-number(./OrderReferences, "#00")'/>
<xsl:variable name="ref1" select="normalize-space(./Supplier/SupplierReferences)"/>


<xsl:for-each select="./OrderLine">
<xsl:value-of select="$ref"/>
<xsl:value-of select="$ref1"/>
<xsl:value-of select="normalize-space(LineNumber)"/><xsl:text/>
<xsl:value-of select="normalize-space(Product)"/><xsl:text/>
<xsl:value-of select="normalize-space(Quantity)"/>#013;<xsl:text/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

mhkay sorry to bother you again how do i format this node OrderReferences to:

0032761186450285.0000
0032761286450222.0000

I only can put 0 on the right side and not in the left side.
Thank you



Reply With Quote
  #5 (permalink)  
Old September 14th, 2006, 09:28 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<xsl:variable name="ref" select="concat('00',normalize-space(./OrderReferences))"/>

I did it, but if there is a better way , please tell me
Thank you.

Reply With Quote
  #6 (permalink)  
Old September 14th, 2006, 09:40 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can force OrderReferences to six digits using

format-number(OrderReferences, '000000')

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
Copy parent node and not its children bonekrusher XSLT 4 August 29th, 2007 08:44 AM
Copy all contents except current node in XSLT 2BOrNot2B XSLT 2 December 19th, 2006 06:44 PM
xsl using variable on a node Debiprasad XSLT 1 June 22nd, 2006 12:20 PM
xsl:copy copies everywhere ravik@olemiss.edu XSLT 1 November 11th, 2005 07:44 AM



All times are GMT -4. The time now is 04:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.