XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Alex StarSubject: How can I get a value from the first child node ?
Author: Alex Star
Date: 22 Jun 2007 12:37 PM
In the file below root element <MorganData> has multiple child records where each one is a combination of single <HeaderRecord> and multiple <DataRecord>.
Hovewer, both childs are on the same level.

My question is next: For each <HeaderRecord>, How can I get a value <ClosingBal> from the first child <DataRecord> node only? I do not care about all other nodes, but I need a very first child one.

Here is a structure of the file

<MorganData xmlns="http://3wworld.schemas">
<HeaderRecord xmlns="">
<HeaderRecord_Child1>42929</HeaderRecord_Child1>
</HeaderRecord>
<DataRecord xmlns="">
<SettledCash>129418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2495529</ClosingBal>
</DataRecord>
<DataRecord xmlns="">
<SettledCash>140418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2405529</ClosingBal>
</DataRecord>
<HeaderRecord xmlns="">
<HeaderRecord_Child1>42929</HeaderRecord_Child1>
</HeaderRecord>
<DataRecord xmlns="">
<SettledCash>129418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2495529</ClosingBal>
</DataRecord>
<HeaderRecord xmlns="">
<HeaderRecord_Child1>42929</HeaderRecord_Child1>
</HeaderRecord>
<DataRecord xmlns="">
<SettledCash>141418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2895529</ClosingBal>
</DataRecord>
<DataRecord xmlns="">
<SettledCash>154418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2565529</ClosingBal>
</DataRecord>
<DataRecord xmlns="">
<SettledCash>187418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2125529</ClosingBal>
</DataRecord>
</MorganData>


Postnext
Jamil TaylorSubject: How can I get a value from the first child node ?
Author: Jamil Taylor
Date: 22 Jun 2007 12:58 PM
This would be a heck of a lot easier if your data was in the following format:

<MorganData xmlns="http://3wworld.schemas">
<HeaderRecord xmlns="">
<HeaderRecord_Child1>42929</HeaderRecord_Child1>
<DataRecord xmlns="">
<SettledCash>129418.81</SettledCash>
<DataRecord_Child20>120907.22</DataRecord_Child20>
<ClosingBal>2495529</ClosingBal>
</DataRecord>
</HeaderRecord>
</MorganData>

Where each DataRecord was a child of each associated HeaderRecord.

Since this is not the case, you could keep track of the position of each element in your xpath results. Something like this:

/ns1:MorganData/HeaderRecord[position()=1]/HeaderRecord_Child1

For this header, get the ClosingBal:

/ns1:MorganData/DataRecord[position()=1]/ClosingBal

Postnext
Alex StarSubject: How can I get a value from the first child node ?
Author: Alex Star
Date: 25 Jun 2007 05:57 PM
I am trying to build XSLT template and it is not going well so far.
I do not understand how can I call first <DataRecord> node from the inside a <HeaderRecord> loop.
Here is what I got:


<xsl:for-each select="//HeaderRecord">
<xsl:call-template name="firstnode"/>
<xsl:for-each select="./DataRecord">
<xsl:call-template name="regular"/>
</xsl:for-each><!--for-each DataRecord -->
</xsl:for-each><!--for-each HeaderRecord -->


Inside first "for-each" I got next data:
<HeaderRecord>
<HeaderRecord>
<HeaderRecord>
<HeaderRecord>
<HeaderRecord>
<HeaderRecord>

I want to call template "firstnode" after the each iterations of the "HeaderRecord".
Next step is to get a value from the very first following <DataRecord> node, so my question is how can I access a its value?
The XPath /ns1:MorganData/HeaderRecord[position()=1]/HeaderRecord_Child1 does not work(it is pointed to the wrong node).

As you said, if file would have a different structude, it would be less difficult.
Hovewer, all "HederRecord" and "DataRecord" are on the same level.

Postnext
Jamil TaylorSubject: How can I get a value from the first child node ?
Author: Jamil Taylor
Date: 25 Jun 2007 06:43 PM
Originally Posted: 25 Jun 2007 06:39 PM
My apologies. I thought your data was one header record followed by one data record. The position xpath would have worked in this case, if the position was passed as a parameter to another template.

You can still do something similar though. Like this:

/ns1:MorganData/HeaderRecord[position()=1]/HeaderRecord_Child1/following::DataRecord[position()=1]/ClosingBal

This would retrieve the first ClosingBal following the first HeaderRecord.

/ns1:MorganData/HeaderRecord[position()=2]/HeaderRecord_Child1/following::DataRecord[position()=1]/ClosingBal

This would retrieve the first ClosingBal following the second HeaderRecord, and etc.

So, you can construct a for-each, a template that requires a parameter, pass the position as that parameter, and use a similar xpath as the second example above to retrieve the ClosingBal you are interested in.

Good luck.

Posttop
Alex StarSubject: How can I get a value from the first child node ?
Author: Alex Star
Date: 25 Jun 2007 11:18 PM
Thank you for the help. I finally made it work. I found a different solution. I could actually ignore completelly all "HederRecord" nodes since all information is repeted in the trailing "DataRecord" elements. So, I used next expression to look for new node only and disregards any other following nodes:

<xsl:if test="not(PortfolioID=preceding-sibling::DataRecord/PortfolioID)">
<xsl:call-template name="getfirstnode"/>
</xsl:if>

I am sorry, I did not explained before in more details. Also, the data-sample I gave in the original post does not represent properly a source document I have. Sorry about it.

Best regards,

Alex Star

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.