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

Re: Processing Stylesheet with multiple namespaces

Subject: Re: Processing Stylesheet with multiple namespaces
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Sat, 22 Sep 2007 21:57:21 +0200
Re:  Processing Stylesheet with multiple namespaces
Michael Daniloff wrote:
here it is Joe:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-
com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft
-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
exclude-result-prefixes="ve o r m v wp w10 w wne">


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="w:object">
<w:pict> <xsl:apply-templates/> <xsl:apply-templates select="w:OLEObject"/> <xsl:apply-templates select ="@o:ole"/> </w:pict>
</xsl:template> <xsl:template match="w:OLEObject"/>
<xsl:template match="@o:ole"/>


</xsl:stylesheet>

this version doesn't strip "o:ole" attribute from the
element v:shape

So, I came with this one that does the trick:

<xsl:stylesheet> - (M.D. skipped namespaces
declaration for clarity)

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="w:object">
<w:pict> <xsl:apply-templates/>
<xsl:apply-templates select="v:shape" mode="k"/>
<xsl:apply-templates select="w:OLEObject"/>
</w:pict>
</xsl:template>
<xsl:template match="v:shape" mode="k">
<v:shape>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="@style"/>
</xsl:attribute>
<xsl:apply-templates/>
</v:shape>
</xsl:template>
<xsl:template match="v:shape"/>
<xsl:template match="w:OLEObject"/>
</xsl:stylesheet>


This stylesheet strips everything that I don't need.

But, today I discovered that the source can also
contain o:OLEObject element instead of w:OLEObject

and this of course messes everything up.

I still think that I do something incorrectly with the
regard to the multiple namespaces. The one with the
"o" prefix just doesn't behave the way I expect it to.

Isn't all you need one extra template that looks like this:


<xsl:template match="@o:ole" />

With the copy template in place (you already have that), it will effectively strip all o:ole attributes from your tree. In addition, are you sure you want this:

     <xsl:apply-templates/>
     <xsl:apply-templates select="v:shape" mode="k"/>
     <xsl:apply-templates select="w:OLEObject"/>


because that effectively processes all child nodes of w:object firstly, and then (*after* all childnodes, including v:shape have been processed and gone through the copy template) the v:shape elements again. The is will process w:OLEObject, and throw it away (and the previous call, the first xsl:apply-templates of these three, also processed w:OLEObject and threw it away). Meaning: you can safely remove the third line.


Cheers,
-- Abel Braaksma

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.