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)
-> + How to add page number in to v... (2)
-> + XSL Grouping (7)
-> + Repeat images using FOR EACH l... (7)
-> + How to get File name (2)
-> + image and text on the same lin... (2)
-> + Create XSLT stylesheets for us... (2)
-> + Merge Multiple Files While Che... (2)
-> + xslt 3 level or multi level gr... (6)
-> + How to create xsl which will c... (2)
-> + xsl:variable and Result Tree F... (7)
-> - XSL-FO fo:table continued from... (1)
-> + XSLT Java issue (2)
-> + problem with hyperlink (4)
-> + substring-after function probl... (4)
-> + Xalan Processing (3)
-> + Memory utilization high with m... (2)
-> + check all parent node groups s... (2)
-> + CSV DOC to XML CONVERSION (11)
-> + XSLT: Ordered List (based on r... (4)
-> + XSLT Mapping - Issue (4)
-> + XSL following-sibling, how to ... (5)
-> + need xslt elements help (2)
-> + Dynamic generation of URL in X... (2)
-> + List Created from Section Navi... (2)
-> + xslt elements help (2)
-> + Map field if source is not nul... (3)
-> + XSLT group and sort whith gene... (4)
-> + Nested XML value (2)
-> + Specifying condition with coun... (4)
-> + xsl:function using found in er... (4)
-> + How to remove an unwanted spac... (2)
-> + Question about variable substi... (2)
-> + XSL for Comparing nodes and di... (4)
-> + External lookup list (8)
-> + XSL HTML output now needs to b... (2)
-> + Adding a new sub element to th... (4)
-> + How do I get rid of 'Tip' node... (9)
-> + Trying to dynamically create n... (2)
-> + Display XML link, using XSLT a... (9)
-> + calling templates based on ord... (2)
-> + How to add internal links usin... (4)
-> + How to call user defined java ... (3)
-> + XSLT and WebApps past and futu... (3)
-> + passing condition through java... (3)
-> + Apllying a template from withi... (4)
-> + Getting xsl element in javascr... (3)
-> + The document() function inside... (3)
-> + Footnote text move to para (2)
-> + XSL: multiple element come to ... (3)
-> + How to use following-sibling &... (2)
-> + How to use FOP 0.95 with Stylu... (4)
-> + Error during creating PDF from... (2)
-> + Help creating a comma delimite... (4)
-> + Selective Add using XSLT recur... (3)
-> + Help: convert without parent e... (2)
-> - Correct my substring function ... (1)
-> + Old xsl into reports (4)
-> + How to save xslt converted fil... (3)
-> + How to find non tagging text? (5)
-> + Help: Hex entity to Character... (6)
-> + EDI QUOTES MESSAGE NEED TO REP... (2)
-> + How to convert in multi level ... (4)
-> + Need some help with a styleshe... (3)
-> - Conditional Formattinf Formula... (1)
-> + Creating HTML Unordered LIsts.... (2)
-> + xslt params uknown number of i... (2)
-> + How to use fonts other than ba... (2)
-> - Converting existing HTML into ... (1)
-> + Help to tune up this XSLT (2)
-> + XSLT - is only converting the ... (2)
-> + XSLT Editor tab (4)
-> + Convert multiple files from XM... (2)
-> + how to use in select expressi... (2)
-> + Help needed in XSL transformat... (2)
-> + How to add a string with math ... (5)
-> + How to add a string with math ... (6)
-> - br element (1)
-> + Stylesheet directed terminatio... (2)
-> + Who can help me whit sum funct... (2)
-> + XSLT Works in Stylus Studio, n... (3)
-> - Filter by Attribute (1)
-> + Display x number of items whic... (6)
-> + MultiColumn Reporting (3)
-> + cant get namespace declaration... (3)
-> + Performance xsl:for each and n... (3)
-> + How to assign value to a XSLT ... (3)
-> + Select element value based on ... (2)
-> + Version 10 of Saxon? (8)
-> + How to get the value of a node... (5)
-> + Display Xpath using (4)
-> + XSLT to report (2)
-> + xslt help for a noobie (2)
-> + XSL-FO XML to PDF with XSLT (3)
-> + Using XSLT to transform XML to... (4)
-> + XSLT to sort a list alphabetic... (4)
-> + How to Get Colum Values based ... (2)
-> + non persisting predicate filte... (5)
-> + HTML to XSLT (2)
-> + extra carriage returns in "csv... (2)
-> + extra carriage returns in "csv... (3)
-- Previous [301-320] [321-340] [341-360] 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.