Hi,
I have an XML-file :
<book>
<title>Alaska</title>
</book>
I would like transfer the <book>-elements to <bookname> using an xsl-sheet,
thus producing xml-again. and saving the output in a new xml-file
how can I achieve this ? I don't know how to setup my select-statements
(????) :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select=???? >
<xsl:value-of select=???? />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
another question : is there a way to transform element-tags to uppercase ?
thnx
Chris
Martin Honnen - 29 Nov 2004 18:07 GMT
> I have an XML-file :
> <book>
[quoted text clipped - 5 lines]
>
> how can I achieve this ?
Start with the identity transformation
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
and add a template for <book> elements
<xsl:template match="book">
<bookname>
<xsl:apply-templates select="@* | node()" />
<bookname>
</xsl:template>

Signature
Martin Honnen
http://JavaScript.FAQTs.com/
pete - 29 Nov 2004 18:31 GMT
Chris,
I'm only a beginner with xslt so I'm sure that Martins way is a lot more
efficient than mine. Anyway, here is the xslt code you need:
Pete
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-16" indent="yes"/>
<xsl:template match="/book">
<booklist>
<xsl:for-each select="./title">
<new-title>
<xsl:value-of select="."></xsl:value-of>
</new-title>
</xsl:for-each>
</booklist>
</xsl:template>
</xsl:stylesheet>
> Hi,
>
[quoted text clipped - 23 lines]
>
> Chris
Nigel Armstrong - 30 Nov 2004 18:57 GMT
Hi Chris
For your second point, you can use the translate() and name() functions to
do this. Here's a stylesheet that starts with the Identity transform (lots of
posts about this in this group), adds in another template that matches
elements, then translates the lower case letters to upper case. If you are
working with languages other than English, then you would need to expand the
list appropriately...
HTH
Nigel Armstrong
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{translate(name(), 'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
> Hi,
>
[quoted text clipped - 23 lines]
>
> Chris