xsl-list
[Top] [All Lists]

Re: [xsl] Data Integration at runtime using XSL

2006-09-07 05:26:01

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>

--~------------------------------------------------------------------
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>
--~--