textstring as atributes in xsl

Discussion in 'XML' started by =?ISO-8859-15?Q?Joachim_Wei=DF?=, Apr 1, 2005.

  1. Hi,
    does anybody know a simple solution for this XSL-Problem:

    <xsl:param name='controlName'>theName</xsl:param>
    <xsl:param name='otherOptions'><![CDATA[size="5" value="45"]]></xsl:param>

    these parameters shoul result in sth. like
    <input type="text" name="theName" size="5" value="45" />

    the approach is

    <xsl:element name="input>
    <xsl:attribute name="type">text</xsl:attribute>
    <xsl:attribute name="name"><xsl:value-of select="$controlName"
    /></xsl:attribute>


    how do i get my $otherOptions in here?

    </xsl:element>


    TIA

    Jo
     
    =?ISO-8859-15?Q?Joachim_Wei=DF?=, Apr 1, 2005
    #1
    1. Advertising

  2. Joachim WeiƟ wrote:


    > does anybody know a simple solution for this XSL-Problem:
    >
    > <xsl:param name='controlName'>theName</xsl:param>
    > <xsl:param name='otherOptions'><![CDATA[size="5" value="45"]]></xsl:param>
    >
    > these parameters shoul result in sth. like
    > <input type="text" name="theName" size="5" value="45" />
    >
    > the approach is
    >
    > <xsl:element name="input>
    > <xsl:attribute name="type">text</xsl:attribute>
    > <xsl:attribute name="name"><xsl:value-of select="$controlName"
    > /></xsl:attribute>
    >
    >
    > how do i get my $otherOptions in here?


    Obviously with some text stuffed in a CDATA you simply have unstructured
    text which is not suitable to create structured result nodes of it,
    unless you wrote a parser.
    Why is it not possible for you to continue as with the other parameters,
    e.g.
    <xsl:with-param name="size" select="5" />
    <xsl:with-param name="value" select="45" />
    then you could simply use those parameters as you have done with the
    other parameters.

    There are also ways in XSLT to predefine attribute sets e.g.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:eek:utput method="xml" />

    <xsl:attribute-set name="defaultSize">
    <xsl:attribute name="size">5</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="defaultValue">
    <xsl:attribute name="value">45</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="defaultSizeAndValue"
    use-attribute-sets="defaultSize defaultValue" />

    <xsl:template match="/">
    <results>
    <xsl:call-template name="example">
    <xsl:with-param name="controlName" select="'theName'" />
    </xsl:call-template>
    </results>
    </xsl:template>

    <xsl:template name="example">
    <xsl:param name="controlName" />
    <input type="text" name="{$controlName}"
    xsl:use-attribute-sets="defaultSizeAndValue"></input>
    </xsl:template>

    </xsl:stylesheet>

    although that will not help you as far as I can see if you want to pass
    specific parameter values when calling a template.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 1, 2005
    #2
    1. Advertising

  3. Martin Honnen schrieb:
    >

    ...
    Thanks for your answer!

    My problem is that I don't know the names of the parameters in advance.
    I think, that there is no easy solution for that problem.

    Jo
     
    =?ISO-8859-15?Q?Joachim_Wei=DF?=, Apr 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Flood
    Replies:
    0
    Views:
    1,052
    Kevin Flood
    Sep 8, 2004
  2. Replies:
    1
    Views:
    3,686
    A. Bolmarcich
    May 27, 2005
  3. Balaji
    Replies:
    1
    Views:
    270
    Peter Otten
    Jun 11, 2004
  4. Roman
    Replies:
    3
    Views:
    274
    Roman
    May 16, 2006
  5. Edward
    Replies:
    3
    Views:
    126
    Robert Klemme
    Sep 17, 2006
Loading...

Share This Page