473,411 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Using XSL to delete fixed text in arbitrary elements

Given this:
<a>..<b>..<b/><c>..</c>Stuff<d>..</d>..</a>
and this:
<a>..<b>..<b/>Stuff<d>..</d>..</a>
How can I delete 'Stuff' from both? 'Stuff' always appears in the
content of <a> and before the tag <d>, but there's no way to tell
which of several (approx 6, not just two) alternatives appears before
'Stuff'.

Thanks,
Fred
Jul 20 '05 #1
1 1440

"Fred Bartlett" <ve************@netscape.net> wrote in message
news:ff**************************@posting.google.c om...
Given this:
<a>..<b>..<b/><c>..</c>Stuff<d>..</d>..</a>
and this:
<a>..<b>..<b/>Stuff<d>..</d>..</a>
How can I delete 'Stuff' from both? 'Stuff' always appears in the
content of <a> and before the tag <d>, but there's no way to tell
which of several (approx 6, not just two) alternatives appears before
'Stuff'.

Thanks,
Fred
Both of the above are not well-formed xml documents.

Probably you meant:

<a>..<b>..</b><c>..</c>Stuff<d>..</d>..</a>

instead of
<a>..<b>..<b/><c>..</c>Stuff<d>..</d>..</a>

and

<a>..<b>..</b>Stuff<d>..</d>..</a>
instead of
<a>..<b>..<b/>Stuff<d>..</d>..</a>


The wanted transformation is a simple override of the identity rule:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output omit-xml-declaration="yes"/>

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

<xsl:template match="text()[.='Stuff'][following-sibling::*[self::d]]"/>

</xsl:stylesheet>

In the transformation above an empty rule is added (,which effectively
ignores or discards or "deletes" all matching nodes from the generated
output) matching a text node, whose value is the string 'Stuff' and whose
immediate following sibling is a "d" element.

The results for both xml source documents (corrected to be wellformed) are
respectively:

<a>..<b>..</b><c>..</c><d>..</d>..</a>

and

<a>..<b>..</b><d>..</d>..</a>


Hope this helped.

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Haines Brown | last post by:
I understand that <br /> is marginal in CSS, and so am looking for a substitute for the EOL character. I've failed in both approaches and seek advice. The first thing I tried was to use the...
14
by: Timothy Madden | last post by:
Hello I have a linked list of object of a class. I thought it would be nice to have the destructor delete the whole list when I delete just the first element. I don't want to recursivly destroy...
8
by: Chris Portka | last post by:
I need to be able to allocate large numbers of elements at a time but then delete them one at a time. I have settled on the design of using new to allocate many items at once, but am unsure what...
0
by: bdhassan87 | last post by:
how can i insert data to datagrid from text box using visual basic 6.0
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.