[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl-list Digest 17 Jan 2007 06:10:01 -0000 Issue 1

Subject: Re: xsl-list Digest 17 Jan 2007 06:10:01 -0000 Issue 1020
From: Frank Hopper <frank.hopper@xxxxxx>
Date: Wed, 17 Jan 2007 12:04:50 +0100
 Re: xsl-list Digest 17 Jan 2007 06:10:01 -0000 Issue 1
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@xxxxxxxxxxxxxxxxxxxxxx>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Subject: RE:  Re: xsl-list Digest 16 Jan 2007 06:10:00 -0000 Issue 1019
Message-ID: <005e01c7394f$a6f3e5b0$6401a8c0@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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.