<xsl:template match="p"> not working
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 269
- Joined: Sat Jul 10, 2010 4:03 pm
<xsl:template match="p"> not working
I'm writing an xslt transform to number all the <p> tags in a xml document
My initial script below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xd"
version="1.0">
<xsl:template match="p">
<p><xsl:apply-templates select="node() | @*"/>
</p>
</xsl:template>
<xsl:template match="node() | @*" priority="-1">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
However the template match="p" never is entered?
If I add the TEI namespace
xmlns:tei="http://www.tei-c.org/ns/1.0"
and change the template to match="tei:p" it works,
but then it adds the namespace tags to all the initial <p> <s> and <lb> tags which is bad.
Isn't there a way to match the <p> tags without using the tei namespace, or suppress the namespace info in the output file?
My initial script below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xd"
version="1.0">
<xsl:template match="p">
<p><xsl:apply-templates select="node() | @*"/>
</p>
</xsl:template>
<xsl:template match="node() | @*" priority="-1">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
However the template match="p" never is entered?
If I add the TEI namespace
xmlns:tei="http://www.tei-c.org/ns/1.0"
and change the template to match="tei:p" it works,
but then it adds the namespace tags to all the initial <p> <s> and <lb> tags which is bad.
Isn't there a way to match the <p> tags without using the tei namespace, or suppress the namespace info in the output file?
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: <xsl:template match="p"> not working
Hi,
An XPath which is intended to match an XML element from a namespace must also take the namespace into account when selecting (usually by defining a prefix for it).
In XSLT 2.0 you can add an attribute to the xsl:stylesheet like:
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
so that when the XSLT processor finds unprefixed elements in the XPath expressions it will consider them to be in the default namespace.
You also have to set the default prefix to the TEI namespace:
xmlns="http://www.tei-c.org/ns/1.0"
To process an XSLT 2.0 with Oxygen you have to use the Saxon 9 XSLT (HE, PE or EE) processor in the associated transformation scenario
Regards,
Radu
An XPath which is intended to match an XML element from a namespace must also take the namespace into account when selecting (usually by defining a prefix for it).
In XSLT 2.0 you can add an attribute to the xsl:stylesheet like:
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
so that when the XSLT processor finds unprefixed elements in the XPath expressions it will consider them to be in the default namespace.
You also have to set the default prefix to the TEI namespace:
xmlns="http://www.tei-c.org/ns/1.0"
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0">
<xsl:template match="p">
<p><xsl:apply-templates select="node() | @*"/>
</p>
</xsl:template>
<xsl:template match="node() | @*" priority="-1">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service