xsl-list
[Top] [All Lists]

RE: [xsl] Processing multiple documents

2008-03-01 07:26:15
<xsl:apply-templates select="$wordposition"/>
<xsl:apply-templates select="$doc2/$wordposition"/>

You seem to be imagining that $wordposition refers to the expression in the
<xsl:variable select="">, and this expression will then be evaluated twice,
in different contexts. Wrong: a variable always refers to a value, the
result of evaluating the expression in the select attribute (and the context
for that evaluation is determined by the place where the variable is
declared, not the place where the variable reference is evaluated). So
$wordposition is the same value both times.

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Sean Tiley [mailto:sean(_dot_)tiley(_at_)gmail(_dot_)com] 
Sent: 01 March 2008 11:49
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Processing multiple documents

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:t
bl[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(_dot_)bryan(_at_)gmail(_dot_)com> wrote:
<xsl:apply-templates select="$doc2/xpath follows here"/>

Cheers,
Bryan Rasmussen

On Fri, Feb 29, 2008 at 9:38 PM, Sean Tiley 
<sean(_dot_)tiley(_at_)gmail(_dot_)com> 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:t
c/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(_dot_)tiley(_at_)gmail(_dot_)com

 

--~-----------------------------------------------------------------
-  XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
 To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
 or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
 --~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--
Sean Tiley
sean(_dot_)tiley(_at_)gmail(_dot_)com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>