xsl-list
[Top] [All Lists]

Re: [xsl] sequence of strings

2008-12-02 09:25:38
Florent Georges wrote:
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:

The string is more or less my input. My input is an upcast output document.


    <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[(_at_)key = $style][1]/@name"/>
    </xsl:template>

Yes, Michael had this solution too. I am very glad you made we aware of this possibility.


  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,


Thanks for your help too, Florent.

regards, Ruud

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>