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 July 10th, 2006, 10:37 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help, Combine two like attribute values

Somewhat new to XSLT.

I have an xml file: Note two Workorder_Equipment elements
<Workorder_Equipment>
    <Workorder_ID>436</Workorder_ID>
    <Description>Bunn - B38 - FMD-3*</Description>
</Workorder_Equipment>
<Workorder_Equipment>
    <Workorder_ID>436</Workorder_ID>
    <Description>Bunn - Airpot - An Airpot</Description>
</Workorder_Equipment>

I want to append the description values together to look like:
 <COLUMN name="Description">
<VAL>Bunn - B38 - FMD-3* &lt;BR&gt; Bunn - Airpot - An Airpot</VAL>
 </COLUMN>

When I use concat or the following in the XSLT
<xsl:template match="Data/Workorder_Equipment">
  <COLUMN name=""order_line_problem_desc"">
  <VAL>
   <xsl:value-of select="Description"/>
   <xsl:text> &lt;BR&gt; </xsl:text>
   <xsl:value-of select="Description"/>
  </VAL>
 </COLUMN>
 <COLUMN name="order_line_po_id">
  <VAL>
    <xsl:value-of select="Workorder_ID"/>
    </VAL>
 </COLUMN>
             <xsl:apply-templates/>
   </xsl:template>

I get:

<COLUMN name="order_line_problem_desc">
<VAL>Bunn - B38 - FMD-3* &lt;BR&gt; Bunn - B38 - FMD-3*</VAL>
</COLUMN>

It concats the same value. Is there a way to get the two different values concatenated or appended to each other? Also I from the xml file on out put I get two Wororder_ID values and I only need one.
i.e. <COLUMN name="order_line_po_id"><VAL>436</VAL>
         </COLUMN>
     <COLUMN name="order_line_po_id"><VAL>436</VAL>
         </COLUMN>

The resulting output XML file is used for import into a SQL server.
Thanks

 
Old July 10th, 2006, 11:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Looks like you want to group workorders having the same ID. Grouping in XSLT 1.0 is a bit of a black art: see http://www.jenitennison.com/xslt/grouping. In XSLT 2.0 it's much easier, there's an xsl:for-each-group instruction.

You're showing the template that's activated to process a single workorder at a time. Clearly any grouping or concatenation has to happen at the next level up, when you process a collection of workorders. You haven't shown what the next level up in your XML looks like.

You can concatenate elements using concat() or using a sequence of xsl:value-of elements as you tried. But clearly if you select the same Description element twice then it's going to select the same one each time.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 11:37 AM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply. for space reasons i did not post the next level up but here it is:

<Data>
<Workorder_Equipment>
    <Workorder_ID>436</Workorder_ID>
    <Description>Bunn - B38 - FMD-3*</Description>
</Workorder_Equipment>
<Workorder_Equipment>
    <Workorder_ID>436</Workorder_ID>
    <Description>Bunn - Airpot - An Airpot</Description>
</Workorder_Equipment>
</Data>



 
Old July 10th, 2006, 11:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you just want to solve the concatenation problem and ignore the grouping for now, you can do

<xsl:template match="Data">
  <xsl:for-each select="Workorder_Equipment">
     <xsl:value-of select="Description"/>
     <br/>
  </xsl:for-each>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 02:25 PM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have finished this stylesheet and i want to thank you Michael Kay for the great help. I know this was a simple one but its a step in the right direction for me. I would like to purchase your book.

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW TO: xlate attribute values? Philibuster XSLT 4 August 24th, 2006 12:17 PM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
how to get values depending on the attribute vidhya XSLT 1 July 8th, 2005 03:55 AM
Matching of attribute values gb XSLT 2 February 10th, 2004 04:12 AM
different values with the same attribute name srini XSLT 0 January 21st, 2004 05:21 AM





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