Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming attributes

Status
Not open for further replies.

wow1977

Technical User
May 13, 2007
14
DE
hello all

I have a problem renaming attributes:

simple example.

<rootElement>
<Element1 one="id1" two="id2"> test1.com/>
<rootElement/>

and i need that:

<rootElement>
<Element1 one="id1" two="id3"> test1.co.uk/>
<rootElement/>

is that possible.

I appreciate any help..

greetings
 
[tt]<xsl:template match="@*">
<xsl:choose>
<xsl:when test="name()='two'">
<xsl:attribute name="{name()}">
<xsl:value-of select="'id3'" />
</xsl:attribute>
</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="." />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
[/tt]
 
sorry

i dont want to rename attributes, its the value it has.

<rootElement>
<Element1 one="id1" two="id2"> test1.com/>
<rootElement/>

and i need that:

<rootElement>
<Element1 one="id1" two="id2"> test1.co.uk/>
<rootElement/>

many thx
 
What ever you want, do you see you repeatedly showing a non-sensical xml source???
 
ok ur right!

onece again:

<rootElement>
<Element>
<Element1 one="id1" <some text> two="id2" <test.com>
<Element1 three="id3" <some text> four="id4"> <test1.fr>
<\Element>
<\rootElement>

and i need that:

<rootElement>
<Element>
<Element1 one="id1" <some text> two="id2" <test.com>
<Element1 three="id3" <some text> four="id4"> <test1.co.uk>
<\Element>
<\rootElement>

sorry about that, ur totally right.

thx

 
But I still cannot believe my eyse! Your source file is totally off. Which book do you start learning xml from?
 
sorry but I dont get u, this should highlight the troublem i have. I need to change the extension from .fr to co.uk.
 
That 5 lines represent _no_ xml document. How can it be done changing it using xml technology?
 
ok..i agree, i just changed my xml:

last try ;.)

<rootElement>
<Element>
<Element id="some text" test="false">test.com</Element>
<Element id="sometext" test="true">test.fr</Element>
</rootElement>
want to transform that:


<rootElement>
<Element>
<Element id="some text" test="false">test.com</Element>
<Element id="sometext" test="true">test.co.uk</Element>
</rootElement>

thx once again
 
uups sorry
<rootElement>
<Element id="some text" test="false">test.com</Element>
<Element id="sometext" test="true">test.fr</Element>
</rootElement>
want to transform that:


<rootElement>
<Element id="some text" test="false">test.com</Element>
<Element id="sometext" test="true">test.co.uk</Element>
</rootElement>
 
[tt]<xsl:template match="Element/text()">
<xsl:choose>
<xsl:when test="normalize-space()='test.fr'">
<xsl:value-of select="'test.com.uk'" />
</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="." />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
[/tt]
It is not remotely "renaming attributes" as the title suggests.
 
well, that solution doesn' work

and once again, you are totally right, the title is wrong.

thx
 
>well, that solution doesn' work.
Sure, it depends on how you use it.
 

<xsl:template match="Element/text()">
<xsl:choose>
<xsl:when test="normalize-space()='test.fr'">
<xsl:value-of select="'test.co.uk'" />
</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="." />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

like that !
 
and the error message is : Stylesheet error: Unexpected value


thx
 
But you just copy what I post. So your complete xsl document is?
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl=" xmlns:fo=" xmlns:xs=" xmlns:fn="
<xsl:template match="/">
<xsl:apply-templates select="node()|text()|@*" />
</xsl:template>
<xsl:template match="node()|text()|@*">
<xsl:copy>
....
<xsl:template match="Element/text()">
<xsl:choose>
<xsl:when test="normalize-space()='test.fr'">
<xsl:value-of select="'test.co.uk'" />
</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="." />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
 
i take everything back.

It works fine

million thx
 
Your abridged part is? If it is an identity transformation, it already shows you it works. I cannot guarantee the rest (and the dots).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top