all groups > dotnet xml > november 2004 >
You're in the

dotnet xml

group:

xml -> xml using xslt


xml -> xml using xslt Chris
11/29/2004 4:42:08 PM
dotnet xml:
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

Re: xml -> xml using xslt pete
11/29/2004 6:31:46 PM
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>




[quoted text, click to view]

Re: xml -> xml using xslt Martin Honnen
11/29/2004 7:07:57 PM


[quoted text, click to view]


[quoted text, click to view]

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>





--

Martin Honnen
RE: xml -> xml using xslt Nigel Armstrong
11/30/2004 10:57:03 AM
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>




[quoted text, click to view]
AddThis Social Bookmark Button