Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / November 2004

Tip: Looking for answers? Try searching our database.

xml -> xml using xslt

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris - 29 Nov 2004 16:42 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.