This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
If I do <xsl:apply-templates select="@*"/> I can copy all the attribute and then i can modify attribute by using <xsl:attribute....>
Then I can use
<xsl:apply-atemplates select="*"/> to copy all the elements. But then how do i modify their attributes ??
I tried using <xsl:attribute...> it doesn't work because it assumes I can referring to the attributes of root element instead of the current element/node..
<xsl:apply-atemplates select="*"/> to copy all the elements. But then how do i modify their attributes ??
Declare a template that matches one (or all) of those elements. Then you can copy the elements however you want. If inside that you put <xsl:apply-templates select="@*"/> then you can copy the attributes, or you can declare a template that matches an attribute and does something different.
Hard to be more specific with such an un-specific question.
FY Hsieh
Ranch Hand
Joined: Aug 07, 2006
Posts: 73
posted
0
Originally posted by Paul Clapham: Declare a template that matches one (or all) of those elements. Then you can copy the elements however you want. If inside that you put <xsl:apply-templates select="@*"/> then you can copy the attributes, or you can declare a template that matches an attribute and does something different.
Hard to be more specific with such an un-specific question.
I tried to match "MyElement" then I reset the "MyName" attribute of "MyElement" by a new value. This failed as it complained "unexpected child" for <xsl:attribute name='MyName">. I think it considers "MyName as an attribute of the root element instead of "MyElement"'s. How can I reset "MyElement"'s attribute (suppose I have many attributes so I don't want to hard code separate templates, each one mapping to an attribute (too tedious).
I don't know what it means to "reset" an attribute. But in general if you want to copy an XML from input to output with minor changes, it's best to start with an identity transformation:Then if, for some particular node, you want to do something different than copying it to the output, you write a template that matches that node and does that different thing. For example if you want to do something different for a MyName attribute of a MyElement element then you do this:where the "..." part is what you actually want to do. If you want to do nothing, i.e. exclude the attribute from the output, then put nothing there. I suspect that an <xsl:attribute> element should work in that context.
It might also help you to know that you can write templates that match many different elements: [ August 07, 2006: Message edited by: Paul Clapham ]
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: how to copy and modify element's attribute ?