Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] sequence of strings

From: Florent Georges <lists@------------>
To:
Date: 12/2/2008 2:13:00 PM
Ruud Grosmann wrote:

  Dag Ruud,

> My question is: this solution looks clumsy. How can I improve it?

  I don't have the time to analyze your stylesheet, but a few
remarks...  It seems you use a string to represent structured values.
Why don't you use something structured?  In XSLT 2.0, you can pass a
sequence of strings like this:

    <xsl:with-param name="style" select="'italic', 'bold'"/>

  Unfortunately, you can't have nested sequences, so you can't have
something like, say:

    <!-- Do not try this at home! -->
    <xsl:with-param name="values" select="
        ('style', ('italic', 'bold')),
        ('key',   ('val1', 'val2', ...))"/>

  But you can use several parameters if suitable:

    <xsl:with-param name="style" select="'italic', 'bold'"/>
    <xsl:with-param name="key"   select="'val1', 'val2', ..."/>

  Or you can always use XML:

    <xsl:with-param name="values">
       <style>
          <italic/>
          <bold/>
       </style>
       <key>
          <val1/>
          <val2/>
          ...
       </key>
    </xsl:with-param>

  Instead of contains(), you will then be able to use regular XPath
set operators and mapping techniques:

    <xsl:template name="get_attributes" as="xs:string?">
       <xsl:param name="style" as="xs:string*"/>
       <xsl:variable name="map">
          <i key="bold"   name="BLD"/>
          <i key="italic" name="ITA"/>
       </xsl:variable>
       <xsl:sequence select="$map/i[@key = $style][1]/@name"/>
    </xsl:template>

  And if you use a function instead of a named template, you can use
the following to get the element name (but that's really a matter of
taste):

    my:get-element-name(('bold', 'italic'))

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent