This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Tokenizing IDREFs


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]