xsl-list
[Top] [All Lists]

Re: [xsl] Processing multiple documents

2008-03-01 01:31:15
<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: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(_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>