我查看了多个示例,并尝试了每个示例。不知道我错过了什么。我从其他示例中发现的唯一区别是我在<Line>
下有多个<RecordSet>
个节点。
XML:
<?xml version="1.0" encoding="utf-8"?>
<urn:FlatStructure">
<Recordset>
<Line> 12345678</Line>
<Line> abcdefgh</Line>
</Recordset>
</urn:FlatStructure>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<!-- First Trial -->
<xsl:variable name="newline"><xsl:text>
</xsl:text></xsl:variable>
<xsl:template match="/urn:FlatStructure/RecordSet">
<xsl:value-of select="concat(Line,$newline)" />
</xsl:template>
<!-- Second Trial -->
<xsl:template match="/urn:FlatStructure">
<xsl:apply-templates select="RecordSet/Line" />
</xsl:template>
<!-- Third Trial -->
<xsl:template match="/urn:FlatStructure">
<xsl:value-of select="concat(Line,' ')" />
</xsl:template>
</xsl:stylesheet>
当前文字输出:
12345678 abcdefgh
所需的文字输出:
12345678
abcdefgh
我在XSLT中缺少什么?请让我知道如何更正它。
由于
我看了下面的例子(有些可能是重复的),但没有一个对我有用:
答案 0 :(得分:0)
使用.gameContainer
替换newline变量有什么帮助,比如
因此取代
<xsl:variable name="newline"><xsl:text> </xsl:text></xsl:variable>
带
<xsl:value-of select="concat(Line,' ')" />
这给出了期望的结果。
但是,您的代码有一些名称空间问题需要解决...
因此,将<xsl:value-of select="concat(Line,$newline)" />
命名空间添加到XML
urn:
和像这样的XSLT
<urn:FlatStructure xmlns:urn="http://some.urn">
之后,从XSLT模板中的<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:urn="http://some.urn">
匹配项中删除urn
前缀。
答案 1 :(得分:0)
找到解决方案。循环遍历<Line>
下的每个<Recordset>
节点并选择文本。
XSLT有效:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:urn="someurn">
<xsl:output method="text" />
<xsl:template match="/urn:FlatStructure/Recordset">
<xsl:for-each select="Line">
<xsl:value-of select="text()"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
具有相同名称的多个子节点似乎是个问题。
感谢大家投球。
干杯!