Matching elements with namespace prefix in XSLT

后端 未结 3 526
星月不相逢
星月不相逢 2020-12-19 00:52

This is my xml input.


  

        
相关标签:
3条回答
  • 2020-12-19 01:15

    Try this to ignore the namespace:

    <xsl:template match="*[local-name()='package']">
        <xsl:message>Entering package</xsl:message>
    </xsl:template>
    
    0 讨论(0)
  • 2020-12-19 01:29

    XSLT understands the namespaces QNames which are defined in input XML.

    In addition to the above answer we can give any name to our xsl namespace.

    Input xml has definition as xmlns:dc="http://purl.org/dc/elements/1.1/" and elements are defines as dc prefix

    You can define a stylesheet below :

    <?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:purl="http://purl.org/dc/elements/1.1/"
         xmlns:idpf="http://www.idpf.org/2007/opf">
    <xsl:template match="idpf:package/purl:language">
    <xsl:message>Entering package. Selected Language.</xsl:message>
    </xsl:template>
    
    0 讨论(0)
  • 2020-12-19 01:31

    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>
    
    0 讨论(0)
提交回复
热议问题