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
Marek KucharikSubject: result set to XML
Author: Marek Kucharik
Date: 13 Jun 2005 05:39 AM
hello,

please help me because i getting tired from this :(
i'm beginner :(

source xml:
<Row>
<oa_codesharenumberX0>"0"</oa_codesharenumberX0>
<oa_etaX0>"10:30am"</oa_etaX0>
<oa_flightnumberX0>"OK128"</oa_flightnumberX0>
..
..
..

<oa_codesharenumberX1>"1"</oa_codesharenumberX1>
<oa_etaX1>"10:30am"</oa_etaX1>
<oa_flightnumberX1>"OK130"</oa_flightnumberX1>
..
..
..

<oa_codesharenumberX2>"2"</oa_codesharenumberX2>
<oa_etaX2>"10:30am"</oa_etaX2>
<oa_flightnumberX2>"OK129"</oa_flightnumberX2>
..
..
..

<oa_codesharenumberX3>"3"</oa_codesharenumberX3>
<oa_etaX3>"10:30am"</oa_etaX3>
<oa_flightnumberX3>"OK133"</oa_flightnumberX3>
..
..
..

<oa_codesharenumberX0X0>"0"</oa_codesharenumberX0X0>
<oa_etaX0X0>"10:30am"</oa_etaX0X0>
<oa_flightnumberX0X0>"OK131"</oa_flightnumberX0X0>
..
..
..

<oa_codesharenumberX0X1>"1"</oa_codesharenumberX0X1>
<oa_etaX0X1>"10:30am"</oa_etaX0X1>
<oa_flightnumberX0X1>"OK128"</oa_flightnumberX0X1>
..
..
..

<oa_codesharenumberX0X2>"2"</oa_codesharenumberX0X2>
<oa_etaX0X2>"10:30am"</oa_etaX0X2>
<oa_flightnumberX0X2>"OK130"</oa_flightnumberX0X2>
..
..
..
</Row>
where "X" is delimiter
"X0" - starting point for the first group
"X0X0" - starting point for the second group
only two groups.

target:
<op_turn>
<ot_oa_arrival>
<oa_codesharenumber>"0"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK128"</oa_flightnumber>
<tp_arrival_list>
<tp_arrival>
<oa_codesharenumber>"1"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK130"</oa_flightnumber>
</tp_arrival>
<tp_arrival>
<oa_codesharenumber>"2"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK129"</oa_flightnumber>
</tp_arrival>
<tp_arrival>
<oa_codesharenumber>"3"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK133"</oa_flightnumber>
</tp_arrival>
</tp_arrival_list>
</ot_oa_arrival>
<ot_oa_departure>
<oa_codesharenumber>"0"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK131"</oa_flightnumber>
<tp_departure_list>
<tp_departure>
<oa_codesharenumber>"1"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK128"</oa_flightnumber>
</tp_departure>
<tp_departure>
<oa_codesharenumber>"2"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK130"</oa_flightnumber>
</tp_departure>
</tp_departure_list>
</ot_oa_departure>
</op_turn>

it's very strange because you dont know how many elements will be in each group.
pls help :(

marek

Postnext
Ivan PedruzziSubject: result set to XML
Author: Ivan Pedruzzi
Date: 14 Jun 2005 01:43 AM
Hi Marek,

The following should work for you

Hope this helps
Ivan Pedruzzi
Stylus Studio Team


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<op_turn>
<ot_oa_arrival>
<xsl:apply-templates select="Row/oa_codesharenumberX0">
<xsl:with-param name="index" select="0"/>
</xsl:apply-templates>
<tp_arrival_list>
<xsl:apply-templates select="Row/oa_codesharenumberX1"/>
</tp_arrival_list>
</ot_oa_arrival>
<ot_oa_departure>
<xsl:apply-templates select="Row/oa_codesharenumberX0X0">
<xsl:with-param name="index" select="0"/>
</xsl:apply-templates>
<tp_departure_list>
<xsl:apply-templates select="Row/oa_codesharenumberX0X1"/>
</tp_departure_list>
</ot_oa_departure>
</op_turn>
</xsl:template>

<xsl:template match="*">
<xsl:param name="base"/>
<xsl:param name="index" select="1"/>

<xsl:element name="{translate(local-name(), 'X0123456789', '')}">
<xsl:value-of select="."/>
</xsl:element>

<xsl:for-each select="following-sibling::*[1]">
<xsl:element name="{translate(local-name(), 'X0123456789', '')}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>

<xsl:for-each select="following-sibling::*[2]">
<xsl:element name="{translate(local-name(), 'X0123456789', '')}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>

<xsl:if test="$index &gt; 0">
<xsl:variable name="nodename" select="concat(substring(local-name(), 1, string-length(local-name() ) - 1 ), $index+1)"/>
<xsl:apply-templates select="following-sibling::*[local-name() = $nodename]">
<xsl:with-param name="base" select="$base"/>
<xsl:with-param name="index" select="$index + 1"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

Postnext
Marek KucharikSubject: result set to XML
Author: Marek Kucharik
Date: 14 Jun 2005 05:40 AM
thanks, it works good but there is a problem because you dont know which one element <oa_codesharenumber> or <oa_eta> or something else :(
is the first and there are missing <tp_arrival></tp_arrival> elements
look:
<tp_arrival>
<oa_codesharenumber>"2"</oa_codesharenumber>
<oa_eta>"10:30am"</oa_eta>
<oa_flightnumber>"OK129"</oa_flightnumber>
</tp_arrival>

thanks for your answer

marek

Postnext
Ivan PedruzziSubject: result set to XML
Author: Ivan Pedruzzi
Date: 15 Jun 2005 01:31 AM
Ok given the new requirements try the following

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<op_turn>
<ot_oa_arrival>
<xsl:apply-templates select="Row/*[1]" mode="first_node"/>
<tp_arrival_list>
<xsl:apply-templates select="Row/*[1]">
<xsl:with-param name="element_wrapper" select="'tp_arrival'"/>
</xsl:apply-templates>
</tp_arrival_list>
</ot_oa_arrival>
<ot_oa_departure>
<xsl:apply-templates select="Row/*[1]" mode="first_node">
<xsl:with-param name="group" select="0"/>
</xsl:apply-templates>
<tp_departure_list>
<xsl:apply-templates select="Row/*[1]">
<xsl:with-param name="group" select="0"/>
<xsl:with-param name="element_wrapper" select="'tp_departure'"/>
</xsl:apply-templates>
</tp_departure_list>
</ot_oa_departure>
</op_turn>
</xsl:template>

<xsl:template match="*" mode="first_node">
<xsl:param name="group"/>

<xsl:for-each select=". | following-sibling::*">
<xsl:variable name="group_and_index" select="substring-after(local-name(),'X')"/>
<xsl:variable name="currect_group" select="substring-before($group_and_index, 'X')"/>
<xsl:variable name="current_index">
<xsl:choose>
<xsl:when test="$currect_group = ''">
<xsl:value-of select="$group_and_index"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after($group_and_index, 'X')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:if test="$currect_group = $group and $current_index = '0'">
<xsl:element name="{translate(local-name(), 'X0123456789', '')}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>


<xsl:template match="*">
<xsl:param name="index" select="1"/>
<xsl:param name="group"/>
<xsl:param name="element_wrapper"/>

<xsl:variable name="result">
<xsl:for-each select=". | following-sibling::*">
<xsl:variable name="group_and_index" select="substring-after(local-name(),'X')"/>
<xsl:variable name="currect_group" select="substring-before($group_and_index, 'X')"/>
<xsl:variable name="current_index">
<xsl:choose>
<xsl:when test="$currect_group = ''">
<xsl:value-of select="$group_and_index"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after($group_and_index, 'X')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:if test="$currect_group = $group and $current_index = $index">
<xsl:element name="{translate(local-name(), 'X0123456789', '')}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:variable>

<xsl:if test="$result">
<xsl:element name="{$element_wrapper}">
<xsl:copy-of select="$result"/>
</xsl:element>
</xsl:if>

<xsl:if test="$index &gt; 0">
<xsl:variable name="nodename" select="concat(substring(local-name(), 1, string-length(local-name() ) - 1 ), $index+1)"/>
<xsl:apply-templates select="following-sibling::*[local-name() = $nodename]">
<xsl:with-param name="index" select="$index + 1"/>
<xsl:with-param name="group" select="$group"/>
<xsl:with-param name="element_wrapper" select="$element_wrapper"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

Posttop
Marek KucharikSubject: result set to XML
Author: Marek Kucharik
Date: 15 Jun 2005 03:42 AM
hello,

it works really fine. there is a problem in case you have different counts of arrival and departure groups
where group =
<oa_codesharenumber>"1"</oa_codesharenumber>
<oa_eta>"10:30"</oa_eta>
<oa_flightnumber>"OK120"</oa_flightnumber>

but i'll try to find solution by myself.
thank you very much for your help. you are great!

   
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.