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

Re: Dynamic DTD declaration in output

Subject: Re: Dynamic DTD declaration in output
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 May 2019 06:18:20 -0000
Re:  Dynamic DTD declaration in output
Following is one approach that I can come up with (tested with Xalan-J),

Assuming there's following XSLT stylesheet (main.xsl),

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                         version="1.0">

    <xsl:output doctype-system="/path/to/docs.dtd" method="xml"
encoding="UTF-8" />

    <xsl:template match="test">
         <!-- stylesheet logic -->
    </xsl:template>

</xsl:stylesheet>

Following is a pre-process stylesheet (preprocess.xsl. uses an identity
transform, and modifying the value of attribute xsl:output/@doctype-system
via a stylesheet parameter),

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                         version="1.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:param name="DTDPath"/>

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

    <xsl:template match="@doctype-system">
       <xsl:attribute name="doctype-system">
          <xsl:value-of select="$DTDPath"/>
       </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>

We can then run the transformation as follows,

java org.apache.xalan.xslt.Process -in main.xsl -xsl preprocess.xsl -param
DTDPath mypath.dtd

The output produced by above transformation is following,

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output doctype-system="mypath.dtd" method="xml" encoding="UTF-8"/>

    <xsl:template match="test">
       <!-- stylesheet logic -->
    </xsl:template>

</xsl:stylesheet>

The above output, can then be used to transform your actual XML document.

The above preprocess transformation could be followed by your actual
transformation (the two transformations could be joined via a batch file or
a shell script), to produce the desired output.

On Wed, May 15, 2019 at 11:14 AM Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi
>
>
>
> I've got a simple stylesheet which is executed as a pre-process when XML
> documents are loaded into FrameMaker. At the moment the stylesheet includes
> the line
>
>
>
>     <xsl:output doctype-system="/path/to/docs.dtd" method="xml"
> encoding="UTF-8" />
>
>
>
> Because this stylesheet will be used by different users in several
> different contexts, it would be brilliant if the path to the DTD could be
> parameterised. I know the following is invalid but the purpose of this post
> is to ask if there is any way of engineering an equivalent:
>
>
>
>     <xsl:param name="DefaultDTDPath" />
>
>     <xsl:output doctype-system="{$DefaultDTDPath}" method="xml"
> encoding="UTF-8" />
>
>
>
> XSL version has to be 1.0 or 2.0.
>
>
>
> Thanks
>
> T
>




-- 
Regards,
Mukul Gandhi

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.