copying all attributes in XSLT

R

R

Hello everybody.

I've got my XML file with 'field' node .

Field is transformed with XSLT into paragraph tag in XHTML.

But. A programmer can add various attributes to <field> node, eg.
someone can add 'onclick', 'onmouseover', 'style', 'class', 'align'
attributes and so on. I want to copy all the attributes from <field>
to <p>.
But field has also two attributes that can't be copied: 'id' and
'number'.

And the final question ;-):
How to copy all the attributes without 'id' and 'number' ones?

thanks in advance for any help
best regards
R
 
J

Joris Gillis

Tempore 18:37:57 said:
And the final question ;-):
How to copy all the attributes without 'id' and 'number' ones?
<xsl:copy-of select="@*[not(self::id or self::number)]"/>

regards,
 
M

Martin Honnen

R wrote:

How to copy all the attributes without 'id' and 'number' ones?

<xsl:template match="field">
<p>
<xsl:copy-of select="@*[local-name() != 'id' and local-name() !=
'number']" />
<xsl:apply-templates />
</p>
</xsl:template>
 
D

David Carlisle

Joris Gillis said:
Tempore 18:37:57 said:
And the final question ;-):
How to copy all the attributes without 'id' and 'number' ones?
<xsl:copy-of select="@*[not(self::id or self::number)]"/>


You have to use name()!='id' rather than not(self::id) as self::id
selects elements not attributes.

David
 
J

Joris Gillis

Tempore 23:15:34 said:
And the final question ;-):
How to copy all the attributes without 'id' and 'number' ones?
<xsl:copy-of select="@*[not(self::id or self::number)]"/>

You have to use name()!='id' rather than not(self::id) as self::id
selects elements not attributes.

If that is true - and I do not doubt that you're right - then I've been posting non-working code for months:-(
Yet another bug in my XSLT processor (it select attributes and element in the 'self' axis), I should really consider moving to another...

Thanks for pointing it out.

regards,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top