Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2003, 04:09 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML-to-XML filter

hi, another question.

i would like to convert an XML document to another XML document with only 2 elements (from "front" and "back") that must be changed (to "start" and "end").


XML doc1:
<book>
<front>
<p>paragraph <tag/> text.</p>
<p id="xxx">paragraph M&amp;M.</p>
</front>
<back>
<xtag>data</xtag>
<br/>
<ytag>data</ytag>
</back>
</book>


XML doc2:
<book>
<start>
<p>paragraph <tag/> text.</p>
<p id="xxx">paragraph M&amp;M.</p>
</start>
<end>
<xtag>data</xtag>
<br/>
<ytag>data</ytag>
</end>
</book>


Thanks! ;)
 
Old July 21st, 2003, 04:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The standard procedure is to use the 'identity' template which produces an exact copy and then add on extra template to match the nodes you wish to modify:
Code:
<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="front">
    <start><xsl:apply-templates/></start>
  </xsl:template>

  <xsl:template match="back">
    <end><xsl:apply-templates/></end>
  </xsl:template>
</xsl:stylesheet>
--

Joe
 
Old July 21st, 2003, 05:29 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

After a little experiment I realised that the two apply-templates in the second and third templates should have a select on them:
Code:
<xsl:template match="front">
    <start><xsl:apply-templates select="@*|node()"/></start>
  </xsl:template>

  <xsl:template match="back">
    <end><xsl:apply-templates select="@*|node()"/></end>
  </xsl:template>
With your given example it didn't matter but it could in others.

--

Joe
 
Old July 21st, 2003, 05:34 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks again joe! can you kindly recommend what XSLT processor should i use.
 
Old July 21st, 2003, 05:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What's your scenario, i.e. server-side or client-side and which operating system?

--

Joe
 
Old July 21st, 2003, 05:47 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

client-side, Windows NT
 
Old July 21st, 2003, 05:52 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If possible use Msxml Core Service 4 with the latest sp (2 I believe). For development download the full sdk which comprises the relevant dlls and a good help file. For clients there is a simple cab file for use in web pages and a merge file if you are using a set up package.

--

Joe
 
Old July 21st, 2003, 05:57 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you're a great help joe. thanks a lot!





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
Filter multi-tier XML data island jayme27 XSLT 1 April 22nd, 2006 04:53 AM
Using a varible to filter XML output animus XML 0 March 1st, 2006 02:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.