dynamic xslt attribute name

dynamic xslt attribute name

Post by Gary Tyre » Sat, 05 Jul 2003 00:37:21



does anyone have a way of creating a dynamic xslt attribute name?  the code
below produces the following error message:
To create nodes of type 'ATTRIBUTE', a valid name must be specified.

<xsl:variable name="evtH">
<xsl:value-of select="child::event/attribute::type">
</xsl:variable>

<xsl:attribute name="{$evtH}"><xsl:value-of
select="child::event"/></xsl:attribute>

if the variable assignment is replaced with a literal, ie 'value', then
everything works fine.

thanks in advance for your assistance.

GT

 
 
 

dynamic xslt attribute name

Post by Colin Mackenzi » Sat, 05 Jul 2003 00:49:25


I think you need to post a snippet of XML and the XSL where the variable is
defined and used.
The error is saying that you are not supplign a valid name so it is likely
that the variable does not contain a valid QNAME string.
have you tried outputting the value of the varibale to test it, make sure
there are no leading spaces etc?

Colin


Quote:> does anyone have a way of creating a dynamic xslt attribute name?  the
code
> below produces the following error message:
> To create nodes of type 'ATTRIBUTE', a valid name must be specified.

> <xsl:variable name="evtH">
> <xsl:value-of select="child::event/attribute::type">
> </xsl:variable>

> <xsl:attribute name="{$evtH}"><xsl:value-of
> select="child::event"/></xsl:attribute>

> if the variable assignment is replaced with a literal, ie 'value', then
> everything works fine.

> thanks in advance for your assistance.

> GT


 
 
 

dynamic xslt attribute name

Post by Gary Tyre » Sat, 05 Jul 2003 00:56:17


thanx

I found that when I broke out the code into a template, it worked fine. see
below.

<xsl:template name="set-evt-handler">

<xsl:for-each select="child::event">

<xsl:attribute name="{attribute::type}"><xsl:value-of
select="."/></xsl:attribute>

</xsl:for-each>

 </xsl:template>

GT


Quote:> does anyone have a way of creating a dynamic xslt attribute name?  the
code
> below produces the following error message:
> To create nodes of type 'ATTRIBUTE', a valid name must be specified.

> <xsl:variable name="evtH">
> <xsl:value-of select="child::event/attribute::type">
> </xsl:variable>

> <xsl:attribute name="{$evtH}"><xsl:value-of
> select="child::event"/></xsl:attribute>

> if the variable assignment is replaced with a literal, ie 'value', then
> everything works fine.

> thanks in advance for your assistance.

> GT

 
 
 

1. XSLT - Can you pass an attribute name to a named template??

I wanted to know how to pass the name of an attribute to a named
template, so that the named template could use the name of the
attribute to access that attribute for the current element.  I have an
element called <kpi> that has child elements called <period>.  There
are a number of attributes on the <period> element that I want to
process the same way.  So the named template is going to iterate over
all the period elements of the current <kpi> element and just show the
value of the given attribute.  So as shown below, I want to pass the

template to iterate over all period elements and put the value of the
given attribute into a <td> element for my table.  I want to do this
so then I can call the template again with the next attribute

in XSLT?  I tried setting the parameter as shown and also with it in
single quotes.  Neither seems to work.  Any help??


        <xsl:call-template name="HandleKPI">

                <xsl:with-param name="caption" select="'Total Sales'"/>
        </xsl:call-template>
</xsl:template>

<xsl:template name="HandleKPI">
        <xsl:param name="attributeName"/>      
        <xsl:param name="caption"/>    

        <tr>
        <td><xsl:value-of select="$caption"/></td>
        <xsl:for-each select="period">

                <td><xsl:value-of select="$attributeName"/></td>
        </xsl:for-each>  
        </tr>                    
</xsl:template>

2. HP-95 LX Connectivity Pack Software for MS-DOS

3. Using dynamic attributes in html inside xslt

4. Configuration of 8" drive RICOH 8160

5. XSLT Q: how to set the name of a <xsl:attribute> from variable

6. Printing to Xerox Colour (4CP / C410) Laser printer

7. How I have to declare a DTD with qualified names as attributes names?

8. Alpha emulator ??

9. URGENT - Replacing between element name and attribute name.

10. XSLT: sort-by local-name() and name() causes loss of attrs if text() exists

11. XSLT: Dynamic Sorting, i.e. dynamically construction xslt instructions

12. XSL: Can attributes or attribute names be passed as parameters?

13. unlimited attributes/ random attribute names allowed?