【发布时间】:2018-06-29 03:40:14
【问题描述】:
我有一个 XSLT 转换,我从中提取客户名称详细信息。我正在使用 XSLT 1.0。转换似乎在字符串之间插入了额外的空格。以下示例和详细信息:
XML:
<Root>
<Customer>
<PrimaryGuest>
<FirstName>Jonathan (Jonny)</FirstName>
<LastName>Doe</LastName>
<MiddleName>Lewis</MiddleName>
</PrimaryGuest>
<PrimaryGuest>
<FirstName>Mary</FirstName>
<LastName>Doe</LastName>
<MiddleName>L</MiddleName>
</PrimaryGuest>
</Customer>
</Root>
XSLT:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:exslt="http://exslt.org/common"
xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl xsl xsd exslt"
version="1.0">
<xsl:output omit-xml-declaration="yes" />
<xsl:variable name="TravelerName">
<xsl:choose>
<xsl:when test="$LOB = 11">
<xsl:for-each select="Root/Customer/PrimaryGuest | Root/PriorCustomer/PrimaryGuest">
<xsl:if test="(position() = '1')">[</xsl:if>
<xsl:variable name="FirstName">
<xsl:value-of select="FirstName" />
</xsl:variable>
<xsl:variable name="LastName">
<xsl:value-of select="LastName" />
</xsl:variable>
<xsl:variable name="MiddleName">
<xsl:value-of select="MiddleName" />
</xsl:variable>
<xsl:variable name="SuffixName">
<xsl:value-of select="SuffixName" />
</xsl:variable>
<xsl:variable name="TravelerName">
<xsl:value-of
select="concat('["',$FirstName, '", ', '"', $LastName, '", ', '"', $MiddleName, '", ', '"', $SuffixName, '"]')" />
</xsl:variable>
<xsl:value-of select="$TravelerName" />
<xsl:if test="not(position() = last())">, </xsl:if>
<xsl:if test="(position() = last())">]</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
输出:
TravelerName:[[["Jonathan (Jonny)", "Doe", "Lewis", ""], ["Mary", "Doe", "L", ""] ]]
我尝试了几种不同的方法。如果我看到前导或尾随空格但看不到中间的空格,这对我来说很有意义。任何帮助将不胜感激。
【问题讨论】:
-
您使用的是什么 XSLT 处理器?
-
在我尝试使用“JRE 实例默认值”和“Xalan 2.7.1”的本地 Eclipse 中无法重现。我不确定我的部署环境中有什么。我的战争中没有添加任何处理器。
-
要找出您正在使用的处理器,请将
<xsl:comment select="system-property('xsl:vendor')"/>添加到您的样式表中。 -
我试过
。当我在 Eclipse 中对样式表运行单元测试时,它不会打印任何内容。
标签: xml xslt xml-parsing xslt-1.0