Subject: RE: [xsl] Need help OR'ing in XPATH. From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 23 Mar 2006 12:01:22 -0500 |
Cheers, Wendell
... Firstly, I would try to get the design of the XML changed. It's not a good idea to use mixed content in this way. Mixed content is best used for marking up narrative text where it makes sense to ignore markup if you are only interested in the content, for example it's quite acceptable to say
<xsl:if test="contains(title, 'H2SO4')/>
where the title element might be
<title>The properties of H<sub>2</sub>SO<sub>4</sub></title>
If I come across badly-designed XML, my usual approach is to use a two-phase transformation in which phase 1 cleans up the XML and phase 2 does the transformation proper. The advantage of this is that phase 1 is reusable, it can be used unchanged regardless what transformation you want to do in phase 2. In this case the "correct" markup is probably something like
<owner> <name>aaa <!-- second-->bbb</name> <id>222</id> </owner>
and the transformation to this form can be achieved in XSLT 2.0 using something like:
<xsl:template match="owner"> <xsl:for-each-group select="*" group-adjacent="self::text() or self::comment()"> <xsl:choose> <xsl:when test="current-grouping-key()"> <name><xsl:copy-of select="current-group()"/></name> </xsl:when> <xsl:otherwise> <xsl:copy-of select="current-group()"/> </xsl:otherwise> </ </ </
(you might also have to do something about whitespace-only text nodes, depending on whether they need to be retained)
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Need help OR'ing in XPATH, Wendell Piez | Thread | Re: [Fwd: RE: [xsl] Need help OR'in, Glen Mazza |
Re: [xsl] msxml and removing parame, António Mota | Date | Re: [xsl] xsL:with-param, xsl:-para, Kasimier Buchcik |
Month |