OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: recursive recursion

[ Lists Home | Date Index | Thread Index ]

Using the "str-split-to-words" template from FXSL one would write:


<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">
 <xsl:import href="strSplit-to-Words.xsl"/>
 <xsl:output method="text"/>

 <!-- To be applied on test-strSplit-to-Words8.xml -->

  <xsl:template match="/">
    <xsl:variable name="vrtfVal1">
      <xsl:call-template name="str-split-to-words">
        <xsl:with-param name="pStr" select="/*/@att1"/>
        <xsl:with-param name="pDelimiters" select="';'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="vrtfVal2">
      <xsl:call-template name="str-split-to-words">
        <xsl:with-param name="pStr" select="/*/@att2"/>
        <xsl:with-param name="pDelimiters" select="';'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="vVal1"
     select="msxsl:node-set($vrtfVal1)/word"/>
    <xsl:variable name="vVal2"
     select="msxsl:node-set($vrtfVal2)/word"/>

     <xsl:for-each select="$vVal1">
       <xsl:variable name="vV1" select="."/>

       <xsl:for-each select="$vVal2">
         <xsl:value-of select="concat($vV1, ., ' ')"/>
       </xsl:for-each>
     </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>


When this is applied on the following source.xml:

<elem att1="a;b;c" att2="x;y;z;t"/>


the wanted result is produced:

ax ay az at bx by bz bt cx cy cz ct


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"Ronald Kent Gibson" <Kent.Gibson@icongmbh.de> wrote in message
B153B9FFD8A5D411A1AE0050DA7C3AD034D771@ICON041">news:B153B9FFD8A5D411A1AE0050DA7C3AD034D771@ICON041...
> Dear All,
>
> I suspect that this is a really easy problem, but I am having a problem
> getting my head around the problem.
>
> I have two attributes each with multiple values like x;y;z and a;b.
>
> I want to output every possible permutation of each of these attributes,
for
> example xa,ya,za,xb,yb,zb
>
> So I need to recurse within the recursive algorithmn, but almost every
thing
> I try doesn't work.
>
> Does anyone clever with recursion have some advice.
>
> thanks
>
> kent
>
> Here is some code I tried.
>
> <xsl:call-template name="returnStringBeforeX">
>
>
> <xsl:with-param name="myStringA" select="x;y;z"/>
>
> <xsl:with-param name="myStringB" select="a;b"/>
>
> </xsl:call-template>
>
> <xsl:template name="returnStringBeforeX">
>
> <xsl:param name="myStringA"/>
> <xsl:param name="myStringB"/>
>
> <xsl:choose>
> <!-- This rule fires when threre is something after
> ;, what is on the left is ready so we output this result -->
>
> <xsl:when test="substring-after($myStringA, ';')
> !='' ">
>
> <xsl:value-of select="substring-before($myStringA,
> ';')"/>
> <xsl:value-of select="substring-before($myStringB,
> ';')"/>
>
> <!-- We have not finished recursing so we
> call the funktion again -->
> <xsl:call-template
> name="returnStringBeforeX">
> <xsl:with-param name="myStringA"
> select="substring-after($myStringA, ';')"/>
> <xsl:with-param name="myStringB"
> select="substring-after($myStringB, ';')"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
>
> <!-- We have finished recursing so we output what is
> ready -->
>
> <xsl:value-of select="$myStringA"/>
> <xsl:value-of select="$myStringB"/>
>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
>







 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS