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

RE: Need help OR'ing in XPATH.

Subject: RE: Need help OR'ing in XPATH.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 23 Mar 2006 12:01:22 -0500
RE:  Need help OR'ing in XPATH.
Hi again,

I also note that in this thread Mike has again drawn our attention to XSLT 2.0's strengths in dealing with upconversion problems. Converting Badly-designed XML into Good XML typically involves going uphill. Well-designed XML is like a castle on a hilltop: it can see everything around it for miles, and doesn't need to go up to anywhere.

I've begun telling students that "you know a technology is successful when a lot of people start using it badly". It's unfair to blame XML or XSLT because we see many examples of bad code. Like many young technologies, XSLT 1.0 was designed for a perfect world, in which all XML is well designed. We've now moved beyond that point.

Cheers,
Wendell

At 06:02 AM 3/23/2006, Mike wrote:
... 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.