Xml XSLT得到了一些不需要的值

Xml XSLT得到了一些不需要的值,xml,xslt,Xml,Xslt,XML: 1.1 3232321 12312312-3 1231231231.... 出于某种原因,以下XSL文件始终获取1.1值并将其放在信封元素之前: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE UploadXML SYSTEM "ex_v222.dtd"> <UploadXML><Version>1.1</Version> <Prop

XML:


1.1
3232321
12312312-3
1231231231....
出于某种原因,以下XSL文件始终获取1.1值并将其放在信封元素之前:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE UploadXML SYSTEM "ex_v222.dtd">
    <UploadXML><Version>1.1</Version>
<Properties>
<Property>
<IntegratorID>3232321</IntegratorID>
<IntegratorPropertyID>12312312-3</IntegratorPropertyID>
<IntegratorOfficeID>1231231231</IntegratorOfficeID>....

2312
KKK
。。。。(我认为模板的实现并不重要.)

我得到的是:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:param name="Z">2312</xsl:param>
    <xsl:param name="A">KKK</xsl:param>
    <xsl:output method="xml" encoding="utf-8" indent="yes" />
        <xsl:strip-space elements="*" />

        <xsl:template match='/UploadXML/Properties'> 
        <Envelope>
        <Body>
        <add_adverts>
        <xsl:apply-templates select='Property'/>
        </add_adverts>
        </Body>
        </Envelope>
        </xsl:template>

1.1
。 .

看到1.1了吗?为什么?
有什么想法吗?

您看到了这一点,因为对于不匹配任何模板的节点,这是XSLT的默认行为。要明确不复制版本元素内容,可以使用空模板:

<?xml version="1.0" encoding="utf-8"?>
1.1<Envelope xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <Body>
    <add_adverts>
      <advert>

您需要阅读有关XSLT处理模型的内容,并了解如何使用

观察到的行为是由于文本节点的XSLT内置模板导致的,该模板只是复制它:

<xsl:template match="Version"/>

解决方案是使用具有空正文的模板(不执行任何操作,因此不复制文本节点)覆盖输出中不应出现的任何文本节点的此模板。在这种情况下:

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

太棒了!解决了这个问题。答案将在3分钟内被接受(带有stackoverflow..)
<xsl:template match="Version/text()"/>