Subject: [xsl] 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 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Applying template with a , Abel Braaksma | Thread | [xsl] Clean XSL code for the follow, Karl Stubsjoen |
[xsl] Applying template with a vari, Harry Liljeström | Date | Re: [xsl] saxon xmlspy discrepancy , Colin Adams |
Month |