Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 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 February 13th, 2007, 06:39 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get all elements from XML

Hi there,

I'm posting this on this forum as i'm using a Oracle BPEL application. The application allows you to create and run XSLT transformations.

Here is my problem:

Here is a bit of XML being fed into a XSL transform. I've added spaces for easy reading.

<rootElement>

<ns0:rootData>
<ns0:SYSTEM_NAME>TBA</ns0:SYSTEM_NAME>
<ns0:TAGGED_ITEM_CODE>A-1032</ns0:TAGGED_ITEM_CODE>
</ns0:rootData>

<ns0:rootData>
<ns0:SYSTEM_NAME>TBA2</ns0:SYSTEM_NAME>
<ns0:TAGGED_ITEM_CODE>A-1033</ns0:TAGGED_ITEM_CODE>
</ns0:rootData>

</rootElement>

What i need from the out put is the name of each element and it's variable in a list, with the date and a single result from each data set.
Here is what i need:

<StgEngineeringDataCollection>
<ns0:StgEngineeringData>

<ns0:engName>SYSTEM_NAME</ns0:engName>
<ns0:engValue>TBA</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

<ns0:engName>TAGGED_ITEM_CODE</ns0:engName>
<ns0:engValue>A-1032</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

</ns0:StgEngineeringData>
<ns0:StgEngineeringData>

<ns0:engName>SYSTEM_NAME</ns0:engName>
<ns0:engValue>TBA2</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1033</ns0:tagNo>

<ns0:engName>TAGGED_ITEM_CODE</ns0:engName>
<ns0:engValue>A-1033</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1033</ns0:tagNo>

</ns0:StgEngineeringData>
</StgEngineeringDataCollection>

Ok, notice two things here, that each line of the XML is being outputted and i have no problem writing the XSL for this. In each data set each element's name and value is outputted as <engName> and <engValue>, finally the date is added and a constant <tagNo>.
But the problem is, is the <tagNo> element.
This is constant throughout the process of outputting each element within the set, but changes when you get to the next set of elements.

Here is my current XSL:

<xsl:template match="/">
<ns0:StgEngineeringDataCollection>
<xsl:for-each select="/tns:rootElement/tns:rootData">
<ns0:StgEngineeringData>
<xsl:for-each select="*">
<ns0:engName>
<xsl:value-of select="substring-after(name(.),':')"/>
</ns0:engName>
<ns0:engValue>
<xsl:value-of select="."/>
</ns0:engValue>
<ns0:importDate>
<xsl:value-of select="xp20:current-date()"/>
</ns0:importDate>
<ns0:tagNo>
<xsl:value-of select="tns:TAGGED_ITEM_CODE"/>
</ns0:tagNo>
</xsl:for-each>
</ns0:StgEngineeringData>
</xsl:for-each>
</ns0:StgEngineeringDataCollection>
</xsl:template>

As you can see i've set all paths as relative and the inital for-each loops over the data sets, then the second for-each loops round each element.
BUT tns:TAGGED_ITEM_CODE does not output anything. WHY? Well i guess that's becuase my actually position at each point is on random element which tns:TAGGED_ITEM_CODE doesn't exist on. I can understand that...

So why not make the path to tns:TAGGED_ITEM_CODE fixed, like:
<xsl:value-of select="/tns:rootElement/tns:rootData/tns:TAGGED_ITEM_CODE"/>

BUT, here when the series is outputted it looks like this:


<StgEngineeringDataCollection>
<ns0:StgEngineeringData>

<ns0:engName>SYSTEM_NAME</ns0:engName>
<ns0:engValue>TBA</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

<ns0:engName>TAGGED_ITEM_CODE</ns0:engName>
<ns0:engValue>A-1032</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

</ns0:StgEngineeringData>
<ns0:StgEngineeringData>

<ns0:engName>SYSTEM_NAME</ns0:engName>
<ns0:engValue>TBA2</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

<ns0:engName>TAGGED_ITEM_CODE</ns0:engName>
<ns0:engValue>A-1033</ns0:engValue>
<ns0:importDate>2007-02-09</ns0:importDate>
<ns0:tagNo>A-1032</ns0:tagNo>

</ns0:StgEngineeringData>
</StgEngineeringDataCollection>

NOTE: The <ns0:tagNo> doesn't change, it just stays the same as the first data set, even though i have now looped onto the second data set, with a tagNo as A-1033 NOT A-1032.

So how do i do this. I need to loop down each element outputting the value, but also keep one element fixed as to which set i am in.

Thanks!!!!

o


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
Using xml elements as html attributes chipmaster XSLT 4 June 26th, 2007 10:22 AM
Tags as text in XML elements janise XML 16 January 2nd, 2007 06:45 AM
rearding xml elements chandu.mca007 XML 1 December 16th, 2006 03:14 PM
selecting certain xml elements fogofogo XML 2 December 5th, 2005 07:33 AM



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


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