xml支不支持类似条件判断(if else)的东西,来决定在什么条件下某元素的有效性?

fenex 2003-05-20 01:38:00
即某元素的存在性或哪些元素是有效可用的要依靠之前元素来决定该怎么办?

比如:如果元素A等于a,那么下一个元素是B,否则是元素C。
...全文
762 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcvj 2003-05-22
  • 打赏
  • 举报
回复
<xsl:if> Element
Allows simple conditional template fragments.

<xsl:if
test = boolean-Expression>
</xsl:if>



Example 1 of <xsl:if>
In this example, the names in a group of names are formatted as a comma-separated list.

XML File (names.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="ifcomma.xsl" ?>
<namelist>
<name>Albert</name>
<name>Terrance</name>
<name>Will</name>
<name>Sylvia</name>
<name>Timothy</name>
<name>Gordon</name>
<name>James</name>
<name>Robert</name>
<name>Dan</name>
<name>Sasha</name>
</namelist>
XSLT File (ifcomma.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="namelist/name">
<xsl:apply-templates/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>

</xsl:stylesheet>
Output

This is the formatted output:

Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha

This is the processor output:

<?xml version="1.0" encoding="UTF-16"?>Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha

or using

<xsl:when> Element
Provides multiple conditional testing in conjunction with the <xsl:choose> and <xsl:otherwise> elements.

<xsl:when
test = boolean-Expression>
</xsl:when>
Attributes
test
Required. The condition in the source data to test. If the expression in this attribute evaluates to True when cast to a Boolean, the content of <xsl:when> is instantiated and placed in the output. Node-sets are cast to a Boolean True if they contain at least one node.
vcvj 2003-05-22
  • 打赏
  • 举报
回复
<xsl:if> Element
Allows simple conditional template fragments.

<xsl:if
test = boolean-Expression>
</xsl:if>


test特定格式,= 后是逻辑表达式

In this example, the names in a group of names are formatted as a comma-separated list.

XML File (names.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="ifcomma.xsl" ?>
<namelist>
<name>Albert</name>
<name>Terrance</name>
<name>Will</name>
<name>Sylvia</name>
<name>Timothy</name>
<name>Gordon</name>
<name>James</name>
<name>Robert</name>
<name>Dan</name>
<name>Sasha</name>
</namelist>
XSLT File (ifcomma.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="namelist/name">
<xsl:apply-templates/>
<xsl:if test="position()!=last()">, </xsl:if>
</xsl:template>

</xsl:stylesheet>
Output

This is the formatted output:

Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha

This is the processor output:

<?xml version="1.0" encoding="UTF-16"?>Albert, Terrance, Will, Sylvia, Timothy, Gordon, James, Robert, Dan, Sasha


or using

<xsl:when> Element
Provides multiple conditional testing in conjunction with the <xsl:choose> and <xsl:otherwise> elements.

<xsl:when
test = boolean-Expression>
</xsl:when>
Attributes
test
Required. The condition in the source data to test. If the expression in this attribute evaluates to True when cast to a Boolean, the content of <xsl:when> is instantiated and placed in the output. Node-sets are cast to a Boolean True if they contain at least one node.
孟子E章 2003-05-21
  • 打赏
  • 举报
回复
right
ssm1226 2003-05-20
  • 打赏
  • 举报
回复
<xsl:choose>
<xsl:when test=''>.....</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>

8,909

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧