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

RE: Result tree fragment to string?

Subject: RE: Result tree fragment to string?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 27 Aug 2008 14:06:16 -0400
RE:  Result tree fragment to string?
At 01:47 PM 8/27/2008, Andy wrote:
The above doesn't handle namespaces, processing-instructions, comments,
or mixed content, but it could be hacked to do so.  Is there a reason
why this approach would not work in XSL 1.0 to satisfy his needs?

No, there isn't.


And see http://www.xmlportfolio.com/xml-to-string/.

Martin writes:
Yes, the reason is that you can't do the apply-templates on the result tree fragment, you would first need to convert it to a node-set with an extension function.

This being the case, he could still do tag-writing instead of RTF-building in the logic that created the RTF to begin with:


<xsl:template match="paragraph" mode="HTMLwrite">
  <!-- write an HTML-ish 'p' -->
  <xsl:text>&lt;p></xsl:text>
  <xsl:apply-templates mode="HTMLwrite"/>
  </xsl:text>&lt;/p></xsl:text>
</xsl:template>

Note that:

(a) In the real world, I'd struggle mightily to avoid having to do this. The requirement is fishy, and I'd want to see it justified within a reasonable architecture before I'd willingly code it. This kind of thing is done for bad reasons far more often than for good reasons, and usually shouldn't have to be done at all. (But I can imagine respectable reasons.)

(b) Having accepted the requirement, I'd far sooner do it by pipelining (as suggested by Martin) rather than the hard way, as illustrated here.

(c) If I really had to do it the hard way, I'd probably still write a couple of utility templates so I could do something like:

<xsl:template match="paragraph" mode="HTMLwrite">
  <xsl:call-template name="HTMLtag"/>
    <xsl:with-param name="tag" select="'p'">
    <xsl:with-param name="attributes">
      <xsl:apply-templates select="." mode="HTMLattributes"/>
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

... which is easier to maintain and less prone to break.

Cheers,
Wendell


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