[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Matching sequential elements and suppression of nodes

Subject: Matching sequential elements and suppression of nodes
From: Duncan Anker <danker@xxxxxxxxxxxxx>
Date: Mon, 05 Jun 2006 12:42:43 +1000
xslt select
Hi list,

I am playing around with transforming something like this:

<br />
<br />
<b>word:</b> definition<br />
<b>word:</b> definition<br />
<br />
<br />

into something like this:

<dl>
<dt>word:</dt><dd>definition</dd>
<dt>word:</dt><dd>definition</dd>
</dl>

Thus far, I have a template to match each definition:

 <xsl:template match="b[name(preceding-sibling::*[1]) = 'br']">
 <dt><xsl:value-of select="."  /></dt>
 <dd><xsl:value-of select="following-sibling::text()[1]" /></dd>
 </xsl:template>

It seems to work, in a fashion. It matches <br />foo<b> as well as <br /><b> although I believe I saw a post somewhere in the archives about determining if a text node is whitespace, so if needs be I could test for that instead of being lazy and making assumptions about my data.

What is not so obvious to me is how to stop the following text node from being output twice. I was hoping there was some way to delete a node from the source tree, or mark it as already-processed, or something like that. At the moment the best I can think of is a template that matches text() followed by <br />, although there's no guarantee that that won't be somewhere else in the document where it shouldn't be transformed.

The rule I already have should be restricted to portions of the document as well, since <br /><b> could potentially show up anywhere. I'm thinking that perhaps I should be searching for a <br /><br /> ... <br /><br /> and trying to treat it as a subtree, i.e. wrap it in <dl></dl> and process the contents, then somehow suppress the output of the entire block.

While this type of work is what XSLT is designed for (I assume; maybe it was a prank that was taken seriously), I am unable to see any easy way to handle the case where it is not well-formed XML, rather sequential tags all at the same level. Is it just a matter of writing hideous XPath expressions to traverse up and down the axes?

Regards,
Duncan

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.