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]

RE: document() revisited, final


I don't want to leave this topic without
thanking you for all your help. What may
seem straight-forward to you is not so obvious for
non-programmers like myself. I have now
a solution that works. FYI:

A Perl script reads XHTML files into an XML
file, something like:

<mother>
  <file>files\overview.htm</file>
  <file>files\book1\page1.htm</file>
  <file>files\book1\chap1\page2.htm</file>
</mother>

The meat of my XSL:

<!-- Get attributes -->   
 <xsl:template name="copy.all.attrib">
  <xsl:for-each select="@*">
   <xsl:copy/>
  </xsl:for-each>
 </xsl:template>  
  
 <!-- Define filter, copy results plus attributes --> 
 <xsl:template name="filter">
  <xsl:if test="not(boolean(@lang)) or ( @lang !='german' and @lang
!='french' )">
   <xsl:copy>
    <xsl:call-template name="copy.all.attrib"/>
    <xsl:apply-templates/>
   </xsl:copy>
  </xsl:if>
 </xsl:template>
 
 <!-- Identify old and new contents -->           
  <xsl:template match="file">
    <xsl:variable name="path" select="."/>
    <xsl:variable name="contents" select="document($path)"/>
    <xsl:variable name="newcontents">
      <xsl:for-each select="$contents">
       <xsl:apply-templates select="*"/>
      </xsl:for-each>
    </xsl:variable>
    
 <!-- "The name's Clark. James Clark." -->   
    <xt:document method="html" href="{$path}">
      <xsl:copy-of select="$newcontents"/>
    </xt:document>     
  </xsl:template> 
  
 <!-- Run the filter --> 
  <xsl:template match="*">
    <xsl:call-template name="filter"/>
  </xsl:template>

This has great potential for our "legacy" HTML documentation
(the "lang" and "dir" HTML attributes can be (ab)used for all sorts of
things...)
Thanks again,
Marc


 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]