This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Tokenizing IDREFs
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Tokenizing IDREFs
- From: Stuart Brown <Stuart dot Brown at helicon dot co dot uk>
- Date: Thu, 20 Sep 2001 16:03:41 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
I have an input element with an IDREFS type attribute, and I want to split
it into separate output element/attribute pairs for each individual IDREF
without using xalan: or saxon: extensions (as I want the stylesheet to be
independent of processors).
To change:
<inTag value="ID1 ID2"/>
into
<bag>
<outTag value="ID1"/>
<outTag value="ID2"/>
</bag>
I am using the following (including a test to exclude the <bag> element if
there is only one IDREF):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="tokenize">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,' ')">
<outTag value="{substring-before($string,' ')}"/>
<xsl:call-template name="tokenize">
<xsl:with-param name="string"><xsl:value-of
select="substring-after($string,' ')"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<outTag value="{$string}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="inTag">
<xsl:choose>
<xsl:when test="contains(@value,' ')">
<bag>
<xsl:call-template name="tokenize">
<xsl:with-param name="string"><xsl:value-of
select="@value"/></xsl:with-param>
</xsl:call-template>
</bag>
</xsl:when>
<xsl:otherwise>
<outTag value="{@value}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
However, this clearly only functions where the IDREFs are delimited by a
single space. I am trying to construct a transformation which will work if
the IDREFs are delimited by EITHER a single space OR a line-break, but to
absolutely no success. Any pointers, please?
Stuart
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list