textstring as atributes in xsl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joachim Weiß

    textstring as atributes in xsl

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

    <xsl:param name='controlNa me'>theName</xsl:param>
    <xsl:param name='otherOpti ons'><![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:attribut e name="type">tex t</xsl:attribute>
    <xsl:attribut e name="name"><xs l:value-of select="$contro lName"
    /></xsl:attribute>


    how do i get my $otherOptions in here?

    </xsl:element>


    TIA

    Jo
  • Martin Honnen

    #2
    Re: textstring as atributes in xsl



    Joachim Weiß wrote:

    [color=blue]
    > does anybody know a simple solution for this XSL-Problem:
    >
    > <xsl:param name='controlNa me'>theName</xsl:param>
    > <xsl:param name='otherOpti ons'><![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:attribut e name="type">tex t</xsl:attribute>
    > <xsl:attribut e name="name"><xs l:value-of select="$contro lName"
    > /></xsl:attribute>
    >
    >
    > how do i get my $otherOptions in here?[/color]

    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:styleshe et
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:output method="xml" />

    <xsl:attribut e-set name="defaultSi ze">
    <xsl:attribut e name="size">5</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribut e-set name="defaultVa lue">
    <xsl:attribut e name="value">45 </xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribut e-set name="defaultSi zeAndValue"
    use-attribute-sets="defaultSi ze defaultValue" />

    <xsl:template match="/">
    <results>
    <xsl:call-template name="example">
    <xsl:with-param name="controlNa me" select="'theNam e'" />
    </xsl:call-template>
    </results>
    </xsl:template>

    <xsl:template name="example">
    <xsl:param name="controlNa me" />
    <input type="text" name="{$control Name}"
    xsl:use-attribute-sets="defaultSi zeAndValue"></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

    Comment

    • Joachim Weiß

      #3
      Re: textstring as atributes in xsl

      Martin Honnen schrieb:[color=blue]
      >[/color]
      ...
      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

      Comment

      Working...