[xsl] sequence of strings

Subject: [xsl] sequence of strings
From: Ruud Grosmann <r.grosmann@xxxxxx>
Date: Tue, 02 Dec 2008 14:17:45 +0100
hi group,

I have made a test style sheet to examine how I can use a string value to create nested elements (xslt2, saxon9).
The string contains one or more style descriptors; the needed elements have a different name than the corresponding styles.

My strategy is to convert the string to a sequence of relevant substrings and then to map the sequence to the right element name.

Below I have pasted my stylesheet. For the input document


it creates the expected output

<?xml version="1.0" encoding="utf-8"?>

My question is: this solution looks clumsy. How can I improve it? My focus is not on the nest-template itself, but on the get_attributes-template and the calling of the nest-template (is the extra blop variable needed?)...

thanks in advance, Ruud

<?xml version="1.0" encoding="UTF-8"?> <!-- maak een stack van strings -->

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

  <xsl:template match="/root">
    <xsl:variable name='blop' as='xs:string*'>
      <xsl:call-template name='get_attributes'>
        <!-- make sequence of strings -->
        <xsl:with-param name='string'
                        select='"style: italic;bold"'/>

      <xsl:call-template name='nest'>
        <xsl:with-param name='lijst' select='$blop'/>

  <xsl:template name='nest'>
    <xsl:param name='lijst' select='zip'/>
      <xsl:when test="empty($lijst)">
        <!-- end recursion -->
        <xsl:sequence select="()"/>
        <xsl:element name="{$lijst[1]}">
          <xsl:call-template name='nest'>
            <xsl:with-param name='lijst' select='$lijst[position() != 1]'/>

  <xsl:template name='get_attributes'>
    <xsl:param name='string' select='zip'/>
      <xsl:variable name='blip'
                    select="for $h in ('bold', 'italic') return
                          if (contains($string, $h)) then $h else ()"/>
      <xsl:sequence select="for $h in $blip return if ($h = 'bold') then
                                                        'BLD' else
                              if ($h = 'italic') then 'ITA' else ()" />

Current Thread