[
Lists Home |
Date Index |
Thread Index
]
xsl-list is a better forum for this sort of question -
anyhow it would help to see some xml.
given <elem att1="a;b;c" att2="c;d;e" .../>
and that you want the permutations of all attributes of elem with values
delimited by semicolon (two attributes being a special case):
<xsl:template name="split">
<xsl:param name="prefix"/>
<xsl:param name="str"/>
<xsl:param name="delim"/>
<xsl:choose>
<xsl:when test="contains($str, $delim)">
<xsl:apply-templates select="$prefix" mode="doit"/>
<xsl:apply-templates select="substring-before($str, $delim)" mode="doit"/>
<xsl:text>,</xsl:text>
<xsl:call-template name="split">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="str" select="substring-after($str, $delim)"/>
<xsl:with-param name="delim" select="$delim"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$prefix" mode="doit"/>
<xsl:apply-templates select="$str" mode="doit"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="divide">
<xsl:param name="pre"/>
<xsl:param name="post"/>
<xsl:param name="delim" select="';'"/>
<xsl:choose>
<xsl:when test="contains($pre, $delim)">
<xsl:call-template name="split">
<xsl:with-param name="prefix" select="substring-before($pre, $delim)"/>
<xsl:with-param name="str" select="$post"/>
<xsl:with-param name="delim" select="$delim"/>
</xsl:call-template>
<xsl:call-template name="divide">
<xsl:with-param name="pre" select="substring-after($pre, $delim)"/>
<xsl:with-param name="post" select="$post"/>
<xsl:with-param name="delim" select="$delim"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="split">
<xsl:with-param name="prefix" select="$pre"/>
<xsl:with-param name="str" select="$post"/>
<xsl:with-param name="delim" select="$delim"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="elem/@*">
<xsl:variable name="this" select="."/>
<xsl:for-each select="../@*[name() != name(current())]">
<xsl:call-template name="divide">
<xsl:with-param name="pre" select="$this"/>
<xsl:with-param name="post" select="."/>
</xsl:call-template>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- because i don't know what you want to do with the values -->
<xsl:template match="text()" mode="doit">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="elem">
<xsl:apply-templates select="@*"/>
</xsl:template>
or something.
oops did i overcomplicate things?
sorry it's late, i might have been drinking and of course i've not tested
any of this, but maybe it'll give you some ideas.
though if you're having to process text using xslt you might want an xslt
parser generator [plug warning!] -> http://www.o-xml.org/yapp
best regards,
/m
Martin Klang
http://www.o-xml.org - the object-oriented XML programming language
|