XSL transformation generating output from other nodes

I have the following XSL template (I have omitted the template for organization, let me know if necessary):

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">     
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="SOAP-ENV:Body/*[local-name()='Publisher']">
    <html>      
        <xsl:call-template name="body" />
    </html>     
</xsl:template>
    <xsl:template name="body">
    <BODY>
        <br/>
        <center>
            <font face="arial" size="2">
                <b>Publisher <xsl:value-of select="*[local-name()='Organization']/*[local-name()='PublisherData']/*[local-name()='PublisherName']"/>
                </b>
            </font>
        </center>
        <br/>
        <xsl:apply-templates select="*[local-name()='Organization']"/>
    </BODY>
</xsl:template>
</xsl:stylesheet>

The previous template generates the result that I want by creating tags containing the result generated by the body template. The problem I am facing is that before the opening tag I get the text output from the previous node. Not sure why this is happening since I am not selecting these other nodes. For instance:

<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <SOAP-ENV:Header>
            <n1>abc</n1>
                <n2>def</n2>
        </SOAP-ENV:Header>
        <SOAP-ENV:Body>
            <Publisher>
                          <!--Child nodes here -->
                    </Publisher>
            </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

Given the previous example XML fragment, my output will contain what I would expect from the formatting of a Publisher element, but I also get the text nodes of the child SOAP-ENV elements: Header node.

I only want to convert the contents of the Publisher element, but in the output I get:

abc
def
//Expected output transforming Publisher goes here

: abc def?

+3
1

- , :

XSLT 1.0.

SOAP-ENV:.

<xsl:template match="SOAP-ENV:Header">
</xsl:template>

. XPath , , . local-name(), .

. , /, .

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <html>      
            <xsl:apply-templates select="SOAP-ENV:Body/Publisher" />
        </html>     
    </xsl:template>

    <xsl:template name="Publisher">
        <body>
            <br/>
            <center>
                <font face="arial" size="2">
                    <b>
                        <xsl:text>Publisher </xsl:text>
                        <xsl:value-of select="Organization/PublisherData/PublisherName"/>
                    </b>
                </font>
            </center>
            <br/>
            <xsl:apply-templates select="Organization"/>
        </body>
    </xsl:template>
</xsl:stylesheet>

. , root node. , :

<xsl:template match="*|/">
  <xsl:apply-templates/>
</xsl:template>

, . , node. , m.

<xsl:template match="*|/" mode="m">
  <xsl:apply-templates mode="m"/>
</xsl:template>

, :

<xsl:template match="text()|@*">
  <xsl:value-of select="."/>
</xsl:template>

.

<xsl:template match="processing-instruction()|comment()"/>

. , node; , - , .

, , . .

+3

Source: https://habr.com/ru/post/1736584/


All Articles