|
next
|
Subject: 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 > 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>
|
next
|
Subject: 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 > 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>
|
|
|
|