Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: multi step transformation

From: "Marrow" <m--a-r-r-o-w@--------------------.--->
To: NULL
Date: 10/1/2004 11:18:00 PM
Hi,

Staring with some well-formed XML like...

<?xml version="1.0"?>
<item>
  <a>tom
   dick
   harry
   peter</a>
  <b>typeforA</b>
</item>


Something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <output>
    <xsl:apply-templates select="item"/>
  </output>
</xsl:template>

<xsl:template match="item">
  <xsl:call-template name="splitA">
    <xsl:with-param name="text" select="string(a)"/>
    <xsl:with-param name="type" select="b"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="splitA">
  <xsl:param name="text"/>
  <xsl:param name="type"/>
  <xsl:choose>
    <xsl:when test="contains($text,'&#10;')">
      <a b="{$type}">
        <xsl:value-of
select="normalize-space(substring-before($text,'&#10;'))"/>
      </a>
      <xsl:call-template name="splitA">
        <xsl:with-param name="text"
select="substring-after($text,'&#10;')"/>
        <xsl:with-param name="type" select="$type"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="normalize-space($text)">
      <a b="{$type}">
        <xsl:value-of select="normalize-space($text)"/>
      </a>
    </xsl:when>
  </xsl:choose>

</xsl:template>
</xsl:stylesheet>


HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


"wooks" <wookiz@h...> wrote in message
news:8852d33c.0410010840.2adad030@p......
> have
>
> <a>tom
>    dick
>    harry
>    peter</a>
> <b>typeforA</b>
>
> I want
> <a b="typeforA>tom</a>
> <a b="typeforA>dick</a>
> <a b="typeforA>harry</a>
> <a b="typeforA>peter</a>
>
> I have a generic split routine that works but to get the output I want
> b has to be an attribute of a before the split routine runs. The split
> routine will then add b as an attribute to each A it creates.
>
> Obviously I could do this easily in a 2 step transform -
>
> 1. transform b from an element to an attribute of A.
> 2. Run the split.
>
> But I want to do it in one transform. How?




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent