Xml 根据属性返回值显示是/否
我对XML/XSL是一个全新的概念(比如2天新的)。我在一行中执行xsl:value的select,它返回一个True/False属性。我想让它显示是/否,但我尝试这样做失败。下面是我目前的一行。有人能告诉我需要添加什么来显示是或否吗Xml 根据属性返回值显示是/否,xml,xsl-fo,Xml,Xsl Fo,我对XML/XSL是一个全新的概念(比如2天新的)。我在一行中执行xsl:value的select,它返回一个True/False属性。我想让它显示是/否,但我尝试这样做失败。下面是我目前的一行。有人能告诉我需要添加什么来显示是或否吗 <fo:block>Automatic Sprinklers Required:   <xsl:value-of select="Attributes/AttributeInstance/Attribute[@id=
<fo:block>Automatic Sprinklers Required:  
<xsl:value-of select="Attributes/AttributeInstance/Attribute[@id='1344297']/../Value"/>
</fo:block>
需要自动喷水装置: ;
使用xsl:choose block测试值。choose具有以下语法:
<xsl:choose>
<xsl:when test="some Boolean condition">
<!-- "if" stuff -->
</xsl:when>
<xsl:otherwise>
<!-- "else" stuff -->
</xsl:otherwise>
</xsl:choose>
我重新格式化了您的代码,以调用执行此测试的模板,并根据布尔值打印是/否:
<fo:block>Automatic Sprinklers Required:  
<xsl:call-template name="formatBoolean">
<xsl:with-param name="theBoolValue" select="Attributes/AttributeInstance/Attribute[@id='1344297']/../Value"/>
</xsl:call-template>
</fo:block>
<xsl:template name="formatBoolean">
<xsl:param name="theBoolValue"/>
<xsl:choose>
<xsl:when test="$theBoolValue = true()">
Yes
</xsl:when>
<xsl:otherwise>
No
</xsl:otherwise>
</xsl:choose>
</xsl:template>
需要自动喷水装置: ;
对
不
这段代码应该可以工作,尽管我没有测试它是否有语法错误
祝你好运
Koby使用xsl:choose block测试值。choose具有以下语法:
<xsl:choose>
<xsl:when test="some Boolean condition">
<!-- "if" stuff -->
</xsl:when>
<xsl:otherwise>
<!-- "else" stuff -->
</xsl:otherwise>
</xsl:choose>
我重新格式化了您的代码,以调用执行此测试的模板,并根据布尔值打印是/否:
<fo:block>Automatic Sprinklers Required:  
<xsl:call-template name="formatBoolean">
<xsl:with-param name="theBoolValue" select="Attributes/AttributeInstance/Attribute[@id='1344297']/../Value"/>
</xsl:call-template>
</fo:block>
<xsl:template name="formatBoolean">
<xsl:param name="theBoolValue"/>
<xsl:choose>
<xsl:when test="$theBoolValue = true()">
Yes
</xsl:when>
<xsl:otherwise>
No
</xsl:otherwise>
</xsl:choose>
</xsl:template>
需要自动喷水装置: ;
对
不
这段代码应该可以工作,尽管我没有测试它是否有语法错误
祝你好运
Koby这应该很简单,下面是我的XML:
<form>
<value>False</value>
</form>
错误的
还有我的XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/form/value = 'True'">
<xsl:text>Yes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>No</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
对
不
这应该很简单,下面是我的XML:
<form>
<value>False</value>
</form>
错误的
还有我的XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/form/value = 'True'">
<xsl:text>Yes</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>No</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
对
不
谢谢,我错过了=true()部分,这是一场梦谢谢,我错过了=true()部分,这是一场梦