xsl-list
[Top] [All Lists]

[xsl] Re: xsl-list Digest 17 Jan 2007 06:10:01 -0000 Issue 1020

2007-01-17 04:05:11
It's working now! Thank you so much for your help! Since I am new to XSLT I was really stuck on this for some time. Your advice to use the <debug> instruction was really helpful to me.

The solution looks like this:
----------------------------
WORD2007SAMPLE_DOCUMENT.XML
----------------------------
<?xml version="1.0"?>
<w:document
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";>
   <w:body>
     <w:p>
       <w:customXml w:element="pageTitle">
         <w:r>
           <w:t>1. Web Page Title</w:t>
         </w:r>
       </w:customXml>
     </w:p>
     <w:p>
       <w:r>
         <w:t>Content A</w:t>
       </w:r>
     </w:p>
     <w:p>
       <w:r>
         <w:t>Content B</w:t>
       </w:r>
     </w:p>
     <w:p>
       <w:customXml w:element="pageTitle">
         <w:r>
           <w:t>2. Web Page Title</w:t>
         </w:r>
       </w:customXml>
     </w:p>
     <w:p>
       <w:r>
         <w:t>Content C</w:t>
       </w:r>
     </w:p>
     <w:p>
       <w:r>
         <w:t>Content D</w:t>
       </w:r>
     </w:p>
   </w:body>
</w:document>

----------------------------
OUTPUT.XML
----------------------------
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";>
   <pageData>
     <pageTitle>1. Web Page Title</pageTitle>
     <pageContent>
       Content A and Content B
     </pageContent>
   </pageData>
   <pageData>
     <pageTitle>2. Web Page Title</pageTitle>
     <pageContent>
       Content C and Content D
      </pageContent>
   </pageData>
</root>

----------------------------
TRANSFORM.XSL
----------------------------
<xsl:stylesheet version="2.0"
   xmlns:xsl=http://www.w3.org/1999/XSL/Transform
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";>

   <xsl:output method="xml" indent="yes" encoding="utf-8" />
   <xsl:strip-space elements="*"/>

   <xsl:template match="/">
     <xsl:apply-templates select="//w:body"/>
   </xsl:template>

   <xsl:template match="w:body">
     <root>
       <xsl:for-each-group select="*"
        group-starting-with="w:p[w:customXml/@w:element = 'pageTitle']">
         <pageData>
           <pageTitle>
             <xsl:value-of select="."/>
           </pageTitle>
           <pageContent>
             <xsl:value-of select="current-group()/w:r/w:t"/>
           </pageContent>
         </pageData>
       </xsl:for-each-group>
     </root>
   </xsl:template>
</xsl:stylesheet>

Thanks again,
Frank

------------------------------

Date: Tue, 16 Jan 2007 09:21:05 -0000
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
Subject: RE: [xsl] Re: xsl-list Digest 16 Jan 2007 06:10:00 -0000 Issue 1019
Message-ID: <005e01c7394f$a6f3e5b0$6401a8c0(_at_)turtle>

Sorry if my code was wrong - it does happen! But I can assure you the
principle was sound, it just needs debugging. If you need help debugging it,
it's best if you can post the code as it now stands, because few people are
likely to have the energy to go through the archives.

If you've got a path expression like current-group()/w:p/w:r/w:t that is't
returning anything, quite a good diagnostic technique is to do

<debug>
  <xsl:copy-of select="current-group()"/>
</debug>

which will often reveal where the misunderstanding arose.

Even better, of course, is to write a schema-aware stylesheet in which case
you'll often get an explanation at compile time when you've written a path
expression that can't select anything.

Michael Kay
http://www.saxonica.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>
  • [xsl] Re: xsl-list Digest 17 Jan 2007 06:10:01 -0000 Issue 1020, Frank Hopper <=