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 August 11th, 2008, 12:36 PM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default Removal of series of similarly named nodes

Hello all.
I need to have a series of tags removed from an .xml file using an XSLT transform, but the tags are in such a way:
<Queue0 attributes...>
<Queue1 attributes...>
<Queue2 attributes...>
<etc...etc...>

But there is no guarantee that the same number of Queue tags will be there every time. So essentially I need QueueX number of tags removed. Plus, the parent node <Details> has other children in it in other places that need to be kept.

I have tried this:
<xsl:template match="ErrorLog/Error/Details">
   <xsl:apply-template select="*[starts-with(node(), 'Queue')"] />
</xsl:template>
and the same with contains as well as a number of other ways. But either they don't remove the nodes or they remove all of the children nodes, including the ones I want to keep.

The Queue tags also hold the same attributes, so if there is a way to identify them by the attribute for removal, that would work too.

Any ideas?

 
Old August 11th, 2008, 03:13 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think you mean name() rather than node().

And generally if you want things removed in XSLT you usually try to apply templates to everything else, and then have a blank template for the ones you want to ignore (rather than specifically applying a template to the ones you don't want to do anything with, which seems counter-productive).

/- Sam Judson : Wrox Technical Editor -/
 
Old August 12th, 2008, 10:37 AM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 I think you mean name() rather than node().

And generally if you want things removed in XSLT you usually try to apply templates to everything else, and then have a blank template for the ones you want to ignore (rather than specifically applying a template to the ones you don't want to do anything with, which seems counter-productive).

/- Sam Judson : Wrox Technical Editor -/
I've tried name() before as well. No change.
The rest of what you say is obvious to me. What I'm looking for is a looping algorithm that goes through the xml file, looking for anything with the word 'Queue' as the name of the node. <Queue1> or <Queue2>. I can try to ignore those fields by applying templates to everything else, but without specifying each and every <QueueX> tag, the templates I set up usually remove the other sibling tags that I do not want removed.

Everything I have seen so far, starts-with or contains (or pretty much everything I have seen in tutorials and books), only has string functions that apply to the element of the node or the attributes. But not for the name of the node specifically...unless it's trying to match or select it. Such as, I would like to have...
<xsl:template match="ErrorLog/Error/Queue*">
where the * is for anything that has Queue for the first 5 characters. However, it is becoming apparent that xslt does not allow for this kind of wildcard functionality.


 
Old August 12th, 2008, 10:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Usually in XSLT we process the ones we want to, and ignore the ones we don't want to use - you seemt o be trying to approach it in the reverse.

You can simply start with the identity transform to copy everything:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

Then tell it to ignore things starting with Queue:

<xsl:template match="*[starts-with(name(),'Queue']">

</xsl:template>





/- Sam Judson : Wrox Technical Editor -/
 
Old August 18th, 2008, 07:03 PM
Authorized User
 
Join Date: Aug 2008
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi, I just noticed that you replied.
I'm going to have to try that idea tomorrow. I am not in a position to try it. As it is, I brute forced it by naming each Queue tag.
I'll let you know if it works the way I want it to. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Removal of same tiered nodes, based on text overcast XSLT 2 August 19th, 2008 12:43 PM
namespace removal manish_jaiswal XSLT 5 February 15th, 2008 05:40 AM
Removal of modules slgknjn Excel VBA 0 September 24th, 2004 12:35 AM
Close button removal canuck38 Access 4 July 16th, 2004 03:50 AM





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