Hi David,
I want the output in CSV format. The final output is as follows.
XML used is:
<?xml version="1.0" encoding="UTF-8" ?>
<myelem>
<childelem>
<elemid id='NAME'>ABC</elemid>
<elemid id='AGE'>20</elemid>
</childelem>
<childelem>
<elemid id='NAME'>DEF</elemid>
<elemid id='AGE'>23</elemid>
</childelem>
<childelem>
<elemid id='NAME'>GHI</elemid>
<elemid id='AGE'>15</elemid>
</childelem>
</myelem>
XSL Used is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:variable name="varEmpId">1020|2001|3010</xsl:variable>
<xsl:template match="/">
<xsl:text>Emp Id,Name,Age </xsl:text>
<xsl:for-each select="myelem/childelem">
<xsl:variable name="varString">
<xsl:choose>
<xsl:when test="position()='1'">
<xsl:value-of select="$varEmpId"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($varString, '|')">
<xsl:value-of
select="substring-after($varString, '|')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$varString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="varIndEmpId">
<xsl:choose>
<xsl:when test="contains($varString, '|')">
<xsl:value-of
select="substring-before($varString, '|')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$varString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$varIndEmpId"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="elemid[(_at_)id='NAME']"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="elemid[(_at_)id='AGE']"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output Required is:
Emp Id,Name,Age
1020,ABC,20
2001,DEF,23
3010,GHI,15
Thanks & Regards,
Ambika Prasad Das
-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: Thursday, September 07, 2006 6:13 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Data Integration at runtime using XSL
Or, in XSLT2:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="str" select="'abc|def'"/>
<xsl:variable name="seq" select="tokenize($str,'\|')"/>
<xsl:template match="x">
<x>
<xsl:apply-templates select="main-element"/>
</x>
</xsl:template>
<xsl:template match="main-element">
<xsl:variable name="p" select="position()"/>
<header>
<xsl:value-of select="$seq[min(($p,last()))]"/>
</header>
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
$ saxon8 sigh.xml sigh2.xsl
<?xml version="1.0" encoding="UTF-8"?>
<x>
<header>abc</header>
<main-element>
<fid id="DATA_STATUS">0</fid>
</main-element>
<header>def</header>
<main-element>
<fid id="DATA_STATUS">1</fid>
</main-element>
<header>def</header>
<main-element>
<fid id="DATA_STATUS">2</fid>
</main-element>
</x>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--