You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Wendy Panko <wp...@unity.ncsu.edu> on 2000/06/22 13:55:23 UTC

Write then Read tmp file during processing

Hi,
   I've been using xalan for a while and am very impressed with it. I've 
been able to find a
way to do just about everything I want to do.
   Recently I tried to write a temporary file during processing and was 
unable to read the
document back as I expected.  Was I expecting too much?  Refer to the 
simple test case
below.
   I decided to use a tmp file because I'm processing several xml files and 
wanted a sort of
cheat sheet with the information that I frequently use.  If you know of a 
better way to do
something like that please let me know.
Thanks,
   Wendy Panko
   wpanko@unity.ncsu.edu
   Web Content Developer
   North Carolina State University
   (919) 513-4009


<!-- *** Data file data.xml ****************************** -->
<?xml version='1.0'?>

<!DOCTYPE data [
<!ELEMENT data (current*)>
<!ELEMENT current EMPTY>
<!ATTLIST current
number ID #REQUIRED
 >
]>

<data>
   <current number='one'/>
   <current number='two'/>
   <current number='three'/>
   <current number='four'/>
   <current number='five'/>
</data>

<!-- *** Stylesheet style.xsl ****************************** -->
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                   version="1.0"
                   xmlns:lxslt="http://xml.apache.org/xslt"
                   xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
                   extension-element-prefixes="redirect">

<xsl:template match="data">
   <xsl:apply-templates select="current"/>
   </xsl:template>

<xsl:template match="current">

<!-- Print the number that is being written to the tmp file -->
<xsl:message><xsl:text>Expect: </xsl:text><xsl:value-of 
select="@number"/></xsl:message>

<!-- Write to the tmp file -->
<redirect:write file='tmp.xml'>
   <xsl:element name='current'><xsl:value-of select="@number"/></xsl:element>
   </redirect:write>

<!-- Read from the tmp file and display the result -->
<xsl:message><xsl:text>  Read: </xsl:text><xsl:value-of

select="document('tmp.xml')/current"/></xsl:message>
</xsl:template>

</xsl:stylesheet>


<!- *** Output ******************************* -->
<!-- Output from above
java -classpath xerces.jar;xalan.jar;bsf.jar org.apache.xalan.xslt.Process 
-in data.xml -xsl

style.xsl

Expect: one
   Read: one
Expect: two
   Read: one
Expect: three
   Read: one
Expect: four
   Read: one
Expect: five
   Read: one
-->

<!-- Note: output with the a slightly different template is shown below

<xsl:template match="current">
<!-- This template does not write an initial message stating what is being 
written -->
<redirect:write file='tmp.xml'>
   <xsl:element name='current'><xsl:value-of select="@number"/></xsl:element>
   </redirect:write>
<xsl:message>
   <xsl:text>Read: </xsl:text><xsl:value-of 
select="document('tmp.xml')/current"/>
   <xsl:text> Expected: </xsl:text><xsl:value-of select="@number"/>
   </xsl:message>
</xsl:template>

XSL Warning: Can not load requested doc: file:tmp.xml
  Read:  Expected: one
  Read: two Expected: two
  Read: two Expected: three
  Read: two Expected: four
  Read: two Expected: five
-->