Re: [xsl] Data Integration at runtime using XSL

Subject: Re: [xsl] Data Integration at runtime using XSL
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 7 Sep 2006 13:25:46 +0100
It's much better if you post sample input that's well formed, then
people can use it to test possible answers. Your input had multiple top
level elements and spaces after </ neither of which are allowed in XML.

As I posted the other day, to do this in xlst1, just process elements
one at a time working along the following-sibling axis, passing the
string as a parameter.

<x>

<main-element>
<fid id='DATA_STATUS'>0</fid>
</main-element >

<main-element>
<fid id='DATA_STATUS'>1</fid>
</main-element >

<main-element>
<fid id='DATA_STATUS'>2</fid>
</main-element >

</x>



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="x">
    <x>
      <xsl:apply-templates select="*[1]">
     <xsl:with-param name="str" select="'abc|def'"/>
      </xsl:apply-templates>
    </x>
  </xsl:template>

 <xsl:template match="main-element">
   <xsl:param name="str"/>
   <header>
     <xsl:value-of select="substring-before(concat($str,'|'),'|')"/>
   </header>
   <xsl:variable name="newstr">
     <xsl:choose>
       <xsl:when test="contains($str,'|')">
	 <xsl:value-of select="substring-after($str,'|')"/>
       </xsl:when>
       <xsl:otherwise>
	  <xsl:value-of select="$str"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:copy-of select="."/>
   <xsl:apply-templates select="following-sibling::*[1]">
     <xsl:with-param name="str" select="$newstr"/>
   </xsl:apply-templates>
  </xsl:template>


</xsl:stylesheet>



$ saxon sigh.xml sigh.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>

Current Thread