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!

changing extensions

Status
Not open for further replies.

xslnew1

Technical User
May 28, 2007
10
DE
hello all,

i have a problem changing extension of an text element.

I hope someone can help me.

The situation is as follwing:

xml-input:

<Elements>
<Element type="any" isReadable="true"> ElementName
<Element type="all" isValide="true"> Element_xy.html
</Element>
</Elemenst>

desired xml-output:

<Elements>
<Element type="any" isReadable="true"> ElementName
<Element type="all" isValide="true"> Element_xy.xhtml
</Element>
</Elemenst>
so i need to change the extension to xhtml.

I appreaciata any help.

Thanx
 
I made an mistake, this one isnot a valide document at all:

the right one is :

<Elements>
<Element type="any" isReadable="true"> ElementName
</Element>
<Element type="all" isValide="true"> Element_xy.html
</Element>
</Elements>

desired xml-output:

<Elements>
<Element type="any" isReadable="true"> ElementName
</Element>
<Element type="all" isValide="true"> Element_xy.xhtml
</Element>
</Elemenst>

thanks in advance for any help
 
The special template to do the substitution can be something like this.
[tt]
<xsl:template match="Element/text()">
<xsl:variable name="s" select="normalize-space()" />
<xsl:choose>
<xsl:when test="substring($s,string-length($s)-5+1,5)='.html'">
<xsl:value-of select="concat(substring($s,1,string-length($s)-5),'.xhtml')" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$s" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
[/tt]
Add it to the rest with high enough priority. The rest may be just an identity transformation.
 
thx, that works fine.
I have another problem similiar to the one i posted already.

<Elements>
<Element type="any" isReadable="true"> ElementName.html
</Element>
<Element type="all" isValide="true"> Element_xy.html
</Element>
</Elements>

desired xml-output:

<Elements>
<Element type="any" isReadable="true"> ElementName.html
</Element>
<Element type="all" isValide="true"> Element_xy.xhtml
</Element>
</Elemenst>

well, i wonder if its possible just to rename the second Text in the Element.

Many thx in advance.
 
The question is asked with condition so very non-generic, so are you going to keep on asking with conditions on attributes etc...?
[tt]
<xsl:template match="Element/text()">
<xsl:variable name="s" select="normalize-space()" />
<xsl:choose>
<xsl:when test="count(parent::*/preceding-sibling::Element) = 1">
<xsl:choose>
<xsl:when test="substring($s,string-length($s)-5+1,5)='.html'">
<xsl:value-of select="concat(substring($s,1,string-length($s)-5),'.xhtml')" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$s" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$s" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top