This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

document() and will this cause a problem?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]