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 September 5th, 2006, 04:28 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Filtering an xml with xslt

Hello all,
         I'm working in a xslt file that has to filter some of information included in an xml file.This means that information between some kind of tags and this tags themselves don't have to appear in the output xml.The rest of the information must remain unmodified.

I started using <xsl:value of> for writing the information tha must not be filtered in the output xml file.
I'm sure there is an easier and better way than this approach.

I'm looking for advice on which is the best way to tackle this problem using xslt.

Thanks a lot for the help.

Tomi.

 
Old September 5th, 2006, 04:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The best way of tackling this kind of problem is to write a template rule that copies every element:

<xsl:template match="*">
 <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
 </xsl:copy>
</xsl:template>

and then write further template rules for elements you want to treat differently, for example

<xsl:template match="x"/>

deletes any subtree rooted at an x element, while

<xsl:template match="y">
  <xsl:apply-templates/>
</xsl:template>

processes the children of the y element but drops the y element itself.

If that doesn't help, you'll have to explain your problem more specifically.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 5th, 2006, 06:05 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a problem with <xsl:copy , when I try to copy a node with attributes it only copies the first attribute in the output xml.

i.e

XML INPUT
----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<NodeToCopy a=1.0 b=2.0>
</NodeToCopy>

XML OUTPUT
----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<NodeToCopy a=1.0>
</NodeToCopy>

 
Old September 5th, 2006, 06:12 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My code is as follows:

<xsl:template match="NodeToCopy">

<xsl:copy>
    <xsl:copy-of select="@NodeToCopy"/>
</xsl:copy>

</xsl:template>


 
Old September 5th, 2006, 06:29 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ive solved the problem.

Tomi.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering XML data aldwinenriquez XSLT 7 August 25th, 2008 03:24 AM
XML Filtering BlkR XML 1 June 12th, 2008 05:25 PM
Help with filtering xml jconroy XSLT 6 April 6th, 2008 11:33 PM
filtering xml in using XSLT venjamin XSLT 1 October 20th, 2006 04:21 AM
Filtering XML data based on differnt XML ahmed123 XSLT 5 August 11th, 2006 09:15 AM





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