This is my xml input.
<package version="2.0" unique-identifier="uuid_id"
xmlns="http://www.idpf.org/2007/opf">
<metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:opf="http://www.idpf.org/2007/opf"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<meta name="calibre:series_index" content="1"/>
<dc:language>UND</dc:language>
<dc:creator opf:file-as="Marquez, Gabriel Garcia"
opf:role="aut"
>Gabriel Garcia Marquez</dc:creator>
<meta name="calibre:timestamp" content="2010-07-14T21:35:15.266000+00:00"/>
<dc:title>Cem Anos de Solidão</dc:title>
<meta name="cover" content="cover"/>
<dc:date>2010-07-14T21:35:15.266000+00:00</dc:date>
<dc:contributor opf:role="bkp"
>calibre (0.7.4) [http://calibre-ebook.com]</dc:contributor>
<dc:identifier id="uuid_id" opf:scheme="uuid"
>7e11dc8b-55cb-4411-8f30-df974fbcf58a</dc:identifier>
</metadata>
<manifest>
</package>
and my xslt starts like..
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="package">
<xsl:message>Entering package</xsl:message>
</xsl:template>
I am using XSLT 1.0
and the template package is not getting matched. When I remove the namespace xmlns="http://www.idpf.org/2007/opf"
in package node, the template gets matched. How I can make my template to match without removing the namespaces.
Please help me. Thanks in advance.
In XML a namespace is a collection of names used for elements and attributes. A URI (usually, a URL) is used to identify a particular collection of names.
Provided that you're using XSLT 2.0, all you have to do is add the xpath-default-namespace attribute on the document element of each stylesheet: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://example.com"> ...
The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).
The exclude-result-prefixes attribute in both XSLT 1.0 and XSLT 2.0 allows for the exclusion of certain namespace declarations in the output document.
Add the namespaces in your stylesheet.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:opf="http://www.idpf.org/2007/opf">
<xsl:template match="opf:package">
<xsl:message>Entering package</xsl:message>
</xsl:template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With