Re: [xsl] Processing multiple documents

Subject: Re: [xsl] Processing multiple documents
From: "Sean Tiley" <sean.tiley@xxxxxxxxx>
Date: Sat, 1 Mar 2008 06:48:52 -0500
Thanks Brian.

I can now get the processor to process multiple documents.

I was playing around a bit with one of my templates and am seeing
behavior I can not understand.
I have defined 2 variables

 <xsl:variable name="doc2" select="document('TestScript2.xml')"/>
 <xsl:variable name="wordposition"
select="/w:wordDocument/w:body/wx:sect/wx:sub-section/w:tbl[w:tr/w:tc/w:p/w:r/w:t
= 'Test Case ID #']"/>


If I modify the following template

<xsl:template match="@* | node()" >
    <xsl:copy>
     <xsl:apply-templates
select="/w:wordDocument/w:body/wx:sect/wx:sub-section/w:tbl[w:tr/w:tc/w:p/w:r/w:t
= 'Test Case ID #']"/>
    <xsl:apply-templates
select="$doc2/w:wordDocument/w:body/wx:sect/wx:sub-section/w:tbl[w:tr/w:tc/w:p/w:r/w:t
= 'Test Case ID #']"/>
</xsl:template>

I get my expected results

<w:wordDocument>
 <testresults testfile="TestScript.xml">
      <TestCase TestID="TC-01" result="Pass" DateExecuted="2008.02.27"
CriticalIndicator="Y"/>
      etc...
</testresults>
<testresults testfile="TestScript2.xml">
      <TestCase TestID="TC-01" result="DR 1" DateExecuted="2008.02.29"
CriticalIndicator="Y"/>
      etc...
</testresults>
</w:wordDocument>

Both files are getting successfully processed and included
If I change my template to read (using the declared variables)

 <xsl:template match="@* | node()" >
        <xsl:copy>
            <xsl:apply-templates select="$wordposition"/>
            <xsl:apply-templates select="$doc2/$wordposition"/>
        </xsl:copy>
    </xsl:template>

I get results as follows

<w:wordDocument>
<testresults testfile="TestScript.xml">
      <TestCase TestID="TC-01" result="Pass" DateExecuted="2008.02.27"
CriticalIndicator="Y"/>
      etc...
</testresults>
  <testresults testfile="TestScript.xml">
      <TestCase TestID="TC-01" result="Pass" DateExecuted="2008.02.27"
CriticalIndicator="Y"/>
      etc...
</testresults>
</w:wordDocument>

It appears that the first file TestScript.xml is processed twice while
the second is not.
Why might that be?


Thank you.

Sean


On Sat, Mar 1, 2008 at 3:30 AM, bryan rasmussen
<rasmussen.bryan@xxxxxxxxx> wrote:
> <xsl:apply-templates select="$doc2/xpath follows here"/>
>
> Cheers,
> Bryan Rasmussen
>
> On Fri, Feb 29, 2008 at 9:38 PM, Sean Tiley <sean.tiley@xxxxxxxxx> wrote:
> > Hello,
> >  I created a XSL 2.0 stylesheet that processes a MS Word document
> >  (saved in xml format).
> >
> >  Basically I am extracting information,(test case results), from a
> >  table in the document to create xml output in the following format
> >
> >  <?xml version="1.0" encoding="UTF-8"?>
> >  <?mso-application progid="Word.Document"?>
> >  <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
> >                 xmlns:v="urn:schemas-microsoft-com:vml"
> >                 xmlns:w10="urn:schemas-microsoft-com:office:word"
> >                 xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core";
> >                 xmlns:aml="http://schemas.microsoft.com/aml/2001/core";
> >                 xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint";
> >                 xmlns:o="urn:schemas-microsoft-com:office:office"
> >                 xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
> >                 xmlns:st1="urn:schemas-microsoft-com:office:smarttags">
> >    <testresults testfile="TestScript.xml">
> >       <TestCase TestID="TC-01" result="Pass" DateExecuted="2008.02.27"
> >  CriticalIndicator="Y"/>
> >       <TestCase TestID="TC-02" result="Pass" DateExecuted="2008.02.27"
> >  CriticalIndicator="Y"/>
> >       <TestCase TestID="TC-03" result="Pass" DateExecuted="2008.02.27"
> >  CriticalIndicator="N"/>
> >       <TestCase TestID="TC-04" result="Pass" DateExecuted="2008.02.27"
> >  CriticalIndicator="N"/>
> >       <TestCase TestID="TC-05" result="Pass" DateExecuted="2008.02.27"
> >  CriticalIndicator="N"/>
> >    </testresults>
> >  </w:wordDocument>
> >
> >
> >
> >  My stylesheet is as follows.
> >
> >  <?xml version="1.0" encoding="UTF-8"?>
> >  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
> >     xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
> >     xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint";>
> >     <xsl:output method="xml" indent="yes" />
> >
> >     <!-- Main template-->
> >     <xsl:template
> >  match="/w:wordDocument/w:body/wx:sect/wx:sub-section/w:tbl[w:tr/w:tc/w:p/w:r/w:t
> >  = 'Test Case ID #']">
> >         <xsl:element name="testresults">
> >             <xsl:attribute name="testfile" >
> >                 <xsl:value-of select ="tokenize(document-uri(/), '/')[last()]"/>
> >             </xsl:attribute>
> >             <xsl:for-each select="w:tr">
> >                 <xsl:choose>
> >                     <!-- Only process rows with a test case id.  They
> >  begin with TC- -->
> >                     <xsl:when test="w:tc/w:p/w:r[starts-with(w:t,'TC-')]">
> >                         <xsl:element name="TestCase">
> >                             <xsl:attribute name="TestID">
> >                                 <xsl:value-of select="w:tc[1]/w:p/w:r/w:t"/>
> >                             </xsl:attribute>
> >                             <xsl:attribute name="result">
> >                                 <xsl:value-of select="w:tc[6]/w:p/w:r/w:t"/>
> >                             </xsl:attribute>
> >                             <xsl:attribute name="DateExecuted">
> >                                 <xsl:value-of select="w:tc[5]/w:p/w:r/w:t"/>
> >                             </xsl:attribute>
> >                             <xsl:attribute name="CriticalIndicator">
> >                                 <xsl:value-of select="w:tc[7]/w:p/w:r/w:t"/>
> >                             </xsl:attribute>
> >                         </xsl:element>
> >                     </xsl:when>
> >                     <xsl:otherwise/>
> >                 </xsl:choose>
> >             </xsl:for-each>
> >         </xsl:element>
> >     </xsl:template>
> >
> >     <!-- If this is not here I get alot of additional info I do not want-->
> >     <xsl:template match="@* | node()">
> >         <xsl:copy>
> >             <xsl:apply-templates
> >  select="/w:wordDocument/w:body/wx:sect/wx:sub-section/w:tbl[w:tr/w:tc/w:p/w:r/w:t
> >  = 'Test Case ID #']"/>
> >         </xsl:copy>
> >     </xsl:template>
> >  </xsl:stylesheet>
> >
> >
> >  All this works fine.
> >  My issue now is that I want to process multiple documents and merge in
> >  <TestCase/> elements from another test result document.
> >
> >  I know there is the document() function that I can use like the following
> >  <xsl:variable name="doc2" select="document('another.file.xml')
> >
> >  But I am at a loss as to how to tell the processor to apply the
> >  template to that doc as well.
> >
> >  Once I figure that out, I would like to be able to generalize this to
> >  process 1 to N documents in a given directory.
> >
> >  Any guidance is greatly appreciated
> >
> >  --
> >  Sean Tiley
> >  sean.tiley@xxxxxxxxx
>
>



-- 
Sean Tiley
sean.tiley@xxxxxxxxx

Current Thread