我正在尝试使用result-document从XML文件输出制表符分隔的文本文件。但是,输出仍然包含额外的空格和每行末尾的双引号。
<?xml version="1.0" encoding="UTF-8"?>
<feed>
<entry>
<properties>
<something>HELLO</something>
<Id>1234</Id>
<Email>bob@bobco.com</Email>
</properties>
</entry>
<entry>
<properties>
<something>GOODBYE</something>
<Id>4567</Id>
<Email>carol@bobco.com</Email>
</properties>
</entry>
<entry>
<properties>
<something>HELLO</something>
<Id>8910</Id>
<Email>alice@bobco.com</Email>
</properties>
</entry>
</feed>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no" standalone="yes"/>
<xsl:template match="feed">
<xsl:result-document href="foo.txt" method="text" standalone="yes" indent="no">
<xsl:apply-templates select="entry/properties" />
</xsl:result-document>
</xsl:template>
<xsl:template match="properties" >
<xsl:apply-templates select="Id"/>
<xsl:text>	</xsl:text>
<xsl:apply-templates select="Email" />"
</xsl:template>
<xsl:template match="Id" >
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="Email" >
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="text()|@*"/>
</xsl:stylesheet>
输出:(在第二行和第三行的开头有空格。帐单出来没问题。在缩进设置为"no“的情况下,为什么会有空格,以及如何去掉尾随的双引号?
1234 bob@bobco.com"
4567 carol@bobco.com"
8910 alice@bobco.com"
发布于 2020-08-04 18:16:09
删除match="properties"
模板中的流浪"
字符:
<xsl:apply-templates select="Email" />"
^
它不仅在properties
匹配时被传播,而且还导致下面的空格变得重要并被输出。
https://stackoverflow.com/questions/63252761
复制