【发布时间】:2015-09-03 06:20:28
【问题描述】:
我有以下 XSLT。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dso="http://www.filemaker.com/fmpdsoresult"
exclude-result-prefixes="dso">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="dso:FMPDSORESULT/dso:ROW">
<record>
<First_Name><xsl:value-of select="dso:First_Name"/></First_Name>
<Last_Name><xsl:value-of select="dso:Last_Name"/></Last_Name>
<Address><xsl:value-of select="dso:Address"/></Address>
</record>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
它产生以下输出
<?xml version="1.0" encoding="UTF-8"?>
<record>
<First_Name>John</First_Name>
<Last_Name>Thomas</Last_Name>
<Address>Stuttgart</Address>
</record>
<record>
<First_Name>Aanshi</First_Name>
<Last_Name/>
<Address>Stuttgart</Address>
这里如果数据不可用,那么它只显示结束标记。有没有办法在开始和结束标记之间显示空值。我想要这样的东西
<Address></Address>
另外,如何去除两行之间的空格?
预期输出
<?xml version="1.0" encoding="UTF-8"?>
<record>
<First_Name>John</First_Name>
<Last_Name>Thomas</Last_Name>
<Address>Stuttgart</Address>
</record>
<record>
<First_Name>Aanshi</First_Name>
<Last_Name></Last_Name>
<Address>Stuttgart</Address>
</record>
【问题讨论】:
-
您确定这是一个 XSLT 问题,而不是 Windows 与 Linux、CRLF 与 LF 问题吗?对我来说,它看起来像第二个。 this link help 吗?
-
@torazaburo:是的,你是对的。我已经更新了。
-
remove space between two line是什么意思?什么空间? -
@SeanB.Durkin:我已经更新了问题。
-
嗯?您要求为输出中的空元素提供 html 样式的打开和关闭标签(根据
Address示例),但随后您自相矛盾,表明您想要一个空Last_name元素的自关闭标签。