na********@gmail.com wrote:
Here the action:
I have to browse an XML file with xslt :
For each node i have to determinate if it is a node where
i need to add an attribute...
It's easily done with identity transformation and exclusion
templates. By the way, the wording of your question
probably indicates that you're thinking about your problem
in terms of imperative programming. That's generally a very
bad idea when working with XSLT. You should be thinking in
terms of template matches and selecting nodesets you need,
that'll make it so much easier to figure out how you should
go about your problems.
What is the best manner to browse the xml file? (prefix
browse, postfixe browse??)
I'm not sure what you mean by prefix browse/postfix browse,
or, for that matter, what do you mean by browse where XSLT
is concerned, but as I said, using the identity
transformation seems to be the best way to solve your
problem.
THE XML FILE:
<persone>
<id>123</id>
<name>samantha</name>
<adresse>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
That's not well-formed. It's a good idea to post examples
without obvious, easily fixable mistakes when you're asking
for help. Posting examples *with* obvious, easily fixable
mistakes is a very *bad* idea on the other hand.
<persone id=123>
<id>123</id>
<name>samantha</name>
<adresse id=abc>
<id>abc</id>
<roadwall street </road>
</adresse>
</personne>
That's, uh, even less well-formed. XML 1.0 spec clearly
states (see the AttValue definition) that attribute values
must be enclosed in either quotes or apostrophes.
The following transformation should work:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- exclusion template -->
<xsl:template match="*[id]">
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="id"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
--
Pavel Lepin