[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2004-05-28 14:34 -0700, Mayo wrote:
Then you can have a template rule for each of your custom elements:
<xsl:template match="custom:this">...
<xsl:template match="custom:that">...
<xsl:template match="custom:other">...
... and a catch all for anything unexpected in your custom namespace:
<xsl:template match="custom:*">...
That is only for elements in no namespace.
Careful about using <xsl:copy> as that will also copy all of the in-scope namespaces that are attached to the element as namespace nodes. You might find it safer to do:
as this will not copy any source-tree namespace nodes attached to the current element.
Or you could just add namespace-qualified XHTML elements to your match:
<xsl:template match="*[not(namespace-uri())] | xhtml:*">
with an in-scope declaration of the XHTML namespace URI for that prefix.
To do what? To create an output tree without undesirable namespace nodes? If that is what you are asking for, then use the <xsl:element> instruction above.
When preserving a namespace you cannot use <xsl:copy> without "accidentally" copying all in-scope namespaces. Use the following:
... as this will reconstruct the given source tree element and not have the namespace-node baggage that source tree elements have.
To add a document type declaration, use doctype-system= and optionally doctype-public= to the <xsl:output> instruction.
Specify the document type declaration using <xsl:output> ... the namespaces are managed in XSLT 1 by the implicit copying of elements and the use of namespace= on <xsl:element>, though there are some tricks you can use with <xsl:copy-of/>.
I hope this helps.
....................... Ken
Re: [xsl] Doctype and namespaces in source/generated files
Subject: Re: [xsl] Doctype and namespaces in source/generated files From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 28 May 2004 18:38:04 -0400 |
At 2004-05-28 14:34 -0700, Mayo wrote:
I'm trying to process and output xhtml documents, but I'm having some problems with namespaces. Each source document has extra namespace(s) (other than the xhtml one) for custom tags (the ones that the xslt stylesheet will be processing).
The xslt I'm using matches elements in undefined namespaces, and copies those into the output, and processes the elements in my custom namespaces. (In other words I want to copy everything other than my custom namespaces, and process what's not copied)
Then you can have a template rule for each of your custom elements:
<xsl:template match="custom:this">...
<xsl:template match="custom:that">...
<xsl:template match="custom:other">...
... and a catch all for anything unexpected in your custom namespace:
<xsl:template match="custom:*">...
the match rule i'm using is: <xsl:template match="*[not(namespace-uri())]">
That is only for elements in no namespace.
than I simply xsl:copy, and apply templates.
Careful about using <xsl:copy> as that will also copy all of the in-scope namespaces that are attached to the element as namespace nodes. You might find it safer to do:
<xsl:element name="{local-name(.)}"> <xsl:apply-templates/> </xsl:element>
as this will not copy any source-tree namespace nodes attached to the current element.
This prevents me to specify DOCTYPE or namespaces for xhtml in the source documents, as as soon as I specify them (in the source documents) the match rule will stop working, and strips all my xhtml out.
Or you could just add namespace-qualified XHTML elements to your match:
<xsl:template match="*[not(namespace-uri())] | xhtml:*">
with an in-scope declaration of the XHTML namespace URI for that prefix.
My quesiton is, is there a better way to do this,
To do what? To create an output tree without undesirable namespace nodes? If that is what you are asking for, then use the <xsl:element> instruction above.
or is there any easy way that I can manipulate what namespaces/doctypes the output files will have? (I want to strip out my custom namespaces, preserve any other ones,
When preserving a namespace you cannot use <xsl:copy> without "accidentally" copying all in-scope namespaces. Use the following:
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}"> ...
... as this will reconstruct the given source tree element and not have the namespace-node baggage that source tree elements have.
add the xhtml one, as well as add a doctype to the generated document).
To add a document type declaration, use doctype-system= and optionally doctype-public= to the <xsl:output> instruction.
Ideally, I would like to specify doctype and all the proper namespaces in the source files.
Specify the document type declaration using <xsl:output> ... the namespaces are managed in XSLT 1 by the implicit copying of elements and the use of namespace= on <xsl:element>, though there are some tricks you can use with <xsl:copy-of/>.
I hope this helps.
....................... Ken
-- Public courses: Spring 2004 world tour of hands-on XSL instruction Next: 3-day XSLT/XPath; 2-day XSL-FO - Birmingham, UK June 14,2004
World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Calculating a Moving Aver, Mukul Gandhi | Thread | Re: [xsl] Doctype and namespaces in, Mayo |
RE: [xsl] Doctype and namespaces in, Andreas L. Delmelle | Date | Re: [xsl] Doctype and namespaces in, Mayo |
Month |