This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > May 2004 > xsl:attribute - Set name-attribute via XPath expression?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author xsl:attribute - Set name-attribute via XPath expression?
Christoph Pach

2004-05-20, 7:34 pm

Hi!

I would like to set the name-attribute of a xsl:
attribute-statement via a XPath expression like that:

<xsl:for-each select="//formats/h1/child::*">
<xsl:attribute name="name(self::*)">
<xsl:value-of select="self::*" />
</xsl:attribute>
</xsl:for-each>

But that does not work (using XMLSpy ans FOP), becaus the
parser tells me that "name(self::*)" is an invalid value
for the name-attribute.

So how can I set the name-attribute unsing a XPath
expression?

TIA

Christoph Pach
Joe Fawcett

2004-05-20, 7:34 pm

"Christoph Pach" <anonymous@discussions.microsoft.com> wrote in message
news:f1f201c43da4$e6051480$a601280a@phx.gbl...
> Hi!
>
> I would like to set the name-attribute of a xsl:
> attribute-statement via a XPath expression like that:
>
> <xsl:for-each select="//formats/h1/child::*">
> <xsl:attribute name="name(self::*)">
> <xsl:value-of select="self::*" />
> </xsl:attribute>
> </xsl:for-each>
>
> But that does not work (using XMLSpy ans FOP), becaus the
> parser tells me that "name(self::*)" is an invalid value
> for the name-attribute.
>
> So how can I set the name-attribute unsing a XPath
> expression?
>
> TIA
>
> Christoph Pach

The value of name can be a literal or an atribute-value-template which means
you cn have it dynamically assigned if you surround it in braces, {}:

<xsl:for-each select="//formats/h1/child::*">
<xsl:attribute name="{name(self::*)}">
<xsl:value-of select="self::*" />
</xsl:attribute>
</xsl:for-each>

I'm not sure but wouldn't using just name() and . do as well?

<xsl:for-each select="//formats/h1/child::*">
<xsl:attribute name="{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
--

Joe (MVP - xml)


2004-05-21, 4:29 am

Both versions do work :-)
Many Thanks

Christoph Pach
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews