Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XSL to delete fixed text in arbitrary elements

Reply
Thread Tools

Using XSL to delete fixed text in arbitrary elements

 
 
Fred Bartlett
Guest
Posts: n/a
 
      02-17-2004
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
 
Reply With Quote
 
 
 
 
Dimitre Novatchev [MVP XML]
Guest
Posts: n/a
 
      02-17-2004

"Fred Bartlett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New python module to simulate arbitrary fixed and infinite precisionbinary floating point Rob Clewley Python 2 08-11-2008 05:10 PM
xsl to group elements? [xsl newbie] Rob Smegma XML 1 09-26-2005 10:59 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
calling an arbitrary function w/ arbitrary arguments Honestmath C++ 5 12-13-2004 06:18 AM
XML schemas, including arbitrary elements Laurens XML 2 01-09-2004 01:52 PM



Advertisments