Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2008, 11:14 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Delete all comments in an XSLT file

Hi,

I am trying to write an XSLT to delete all comments in an XSL-FO file. My file is about 25,000 lines of code. I need to delete all the verbose comments. I tried:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions" 
exclude-result-prefixes="xs fn">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:variable name="XML1" select="/"/>
    <xsl:template match="/">
        <xsl:copy-of select="."/>
    </xsl:template>
    <xsl:template match="*">
        <xsl:copy-of select="@*"/>
    </xsl:template>
</xsl:stylesheet>
But this only returns the <fo> namespace, but not all the <xsl>.

thanks for the help.
 
Old February 25th, 2008, 11:23 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Simply start with the identity transform, and then get the stylesheet to skip comments:

<xsl:template match="node()|@*">
   <xsl:copy>
   <xsl:apply-templates select="@*"/>
   <xsl:apply-templates/>
   </xsl:copy>
 </xsl:template>

<xsl:template match="comment()"/>

/- Sam Judson : Wrox Technical Editor -/
 
Old February 25th, 2008, 11:34 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks Sam, but none of my xsl: is being returned. On the FO namespace elements.

 
Old February 25th, 2008, 11:40 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Works fine for me. Can we see your input XML (i.e. the stylesheet you are trying to change).

/- Sam Judson : Wrox Technical Editor -/
 
Old February 25th, 2008, 12:24 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi Sam,

keep in mind my XML input is an XSLT stylesheet that needs the comments remove.

Here is the XSLT that I need the comments removed from:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
 xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <xsl:output version="1.0" method="xhtml" encoding="UTF-8" indent="no"/>
    <xsl:variable name="XML1" select="/"/>
    <xsl:variable name="fo:layout-master-set">

        <fo:layout-master-set>
            <fo:simple-page-master master-name="default-page" page-height="11in" page-width="8.5in" margin-left="0.5in" margin-right="0.5in">
                <fo:region-before extent="0.60in"/>
                <fo:region-body margin-top="0.60in" margin-bottom="0.65in"/>
                <fo:region-after extent="0.65in"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
    </xsl:variable>
    <xsl:template match="/">
        <fo:root>
            <xsl:apply-templates/>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>
 
Old February 25th, 2008, 12:30 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The following stylesheet does the job - I can only assume you have something else in your stylesheet:

Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
   <xsl:copy>
   <xsl:apply-templates select="@*"/>
   <xsl:apply-templates/>
   </xsl:copy>
 </xsl:template>
<xsl:template match="comment()"/>
</xsl:stylesheet>
If that still doesn't work then what XSLT processor are you using?

/- Sam Judson : Wrox Technical Editor -/
 
Old February 25th, 2008, 12:47 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks Sam. I was using XMLspy's processor. I ran it through Saxon 9 and it works fine.

Thanks for the help!








Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to delete file System.IO.Delete error maricar C# 13 March 14th, 2014 06:50 AM
XSLT Node add/delete aintvoguish XSLT 2 December 20th, 2007 03:01 AM
Initial Comments - XSLT 2.0 3rd Ed. baryza Wrox Book Feedback 1 July 9th, 2007 07:18 PM
File Delete qazi_nomi Classic ASP Basics 1 May 17th, 2005 06:54 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.