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

document() and will this cause a problem?

Subject: document() and will this cause a problem?
From: "Basile, Michael" <Basile-Michael@xxxxxxxxxxx>
Date: Thu, 12 Sep 2002 14:15:55 -0400
xsl when test string length
Hi,

 I'm wondering if what I'm doing will get me in to some trouble at some point. Currently everything works, but I'm not sure if it is or isn't because I'm getting lucky.
 
 I have a stylesheet that produces a 'boilerplate' XHTML file which is then modified outside the transformation process. Now, if the transformation is run again, I want to preserve the added content of the existing XHTML by adding it into the newly generated XHTML. I'm doing this using custom tags in the XHTML and grabbing the added content via those tags and the document() function. After looking at the spec, I'm not sure that how I've constructed the stylesheet is 'right'.

 I pass in the name of the XHTML file as a parameter at transform time, then create a variable to hold the node-set created by the document() call. Here's the relevant portions of the stylesheet: 

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ud="http://www.someurl.com/ESD/2002/UserData">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:param name="HTMLMergeFile"/>

<xsl:variable name="MergeXML" select="document($HTMLMergeFile)"/>

<!-- some other templates -->

<xsl:template match="members">
<dl>
<xsl:for-each select="info">
<xsl:variable name="Index" select="position()"/>
<dt><i><xsl:value-of select="."/></i></dt>
<dd>
  <xsl:choose>
   <xsl:when test="string-length(($MergeXML/html/body/descendant::ud:Description)[$Index])&gt;0">
    <xsl:copy-of select="($MergeXML/html/body/descendant::ud:Description)[$Index]"/>
   </xsl:when>
   <xsl:otherwise>
    <ud:Description>TODO - Add Member Description here</ud:Description>
   </xsl:otherwise>
  </xsl:choose>
</dd>
</xsl:for-each>
</dl>
</xsl:template>

</xsl:stylesheet>

 The XHTML would look something like this when output (w/o using the existing XHTML):

 <html xmlns:ud="http://www.someurl.com/ESD/2002/UserData"
 <body>
 <dl><dt><i>MemberInfo</i></dt>
 <dd><ud:Description>TODO - Add Member Description here</ud:Description></dd> 
 </dl> 
 </body>
 </html>

 Now, if I use the existing XHTML, the text of the <ud:Description> element is included in the re-generated 'boilerplate' XHTML of the stylesheet. I should note, when this 'boilerplate' is modified, the TODO part would be changed, or removed (giving me an 'empty' <ud:Description> element). This all works, but I have a few questions:

 1) Am I getting lucky with the document() function?

 What I mean is: I don't pass in the name of an existing XHTML file if one doesn't exist. My understanding of the document() function is that I get a reference to the stylesheet if the 'string' argument is nothing. Is the test "string-length(($MergeXML/html/body/descendant::ud:Description)[$Index])&gt;0" working because my stylesheet doesn't have an html/body/ud:Description node? I don't really understand what's going on here only that it works and I may be benefiting from some side-effect of my stylesheet construction.

 2) Is the 'string-length' test for the existence of a modified <ud:Description> the best way to do check for a modified <ud:Description>?

 Thanks,
  Mike
(I'm on the digest so just reply to the list)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.