xml – XSL if else条件

前端之家收集整理的这篇文章主要介绍了xml – XSL if else条件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个要求,我想有if语句检查一个节点是否有属性或它只有字符串。

例如:节点的1具有找到的0个文件,并且另一个具有诸如< autoincludesystem_info mdate = '08 / 23/2011'mtime = '09:51'ampm​​ ='PM'filesize = '64'filename ='AFP_p.tgp'/>

下面是两个节点的示例

<product>
<autoIncludeUser>0 File(s) found</autoIncludeUser>
<autoIncludeSystem>
<autoincludesystem_info mdate='08/23/2011' mtime='09:51' ampm='PM' filesize='64' filename='AFP_p.tgp' />
<autoincludesystem_info mdate='08/23/2011' mtime='09:51' ampm='PM' filesize='3,879' filename='AnalystsExpressionMacros.tgp' />
<autoincludesystem_info mdate='08/23/2011' mtime='09:51' ampm='PM' filesize='475' filename='base64Converter.tgp' />
<autoincludesystem_info mdate='08/23/2011' mtime='09:51' ampm='PM' filesize='&lt;DIR&gt;' filename='codePages' />
</autoIncludeSystem>
<autoIncludeStudio>0 File(s) found</autoIncludeStudio>
<externalLibrarySystem>
<externalLibrarySystem_info mdate='08/23/2011' mtime='09:52' ampm='PM' filesize='196,608' filename='AFPtoXML_DP.dll' />
<externalLibrarySystem_info mdate='08/23/2011' mtime='09:52' ampm='PM' filesize='13,259' filename='ASN1toXSDRunner.jar' />
<externalLibrarySystem>
</product>

如何识别一个节点是否只有字符串或属性,并且基于我可以分别获得字符串或attrib值。

您可以将整个xsl:choose指令替换为:
<xsl:apply-templates select="autoIncludeSystem"/>

然后添加两个模板:

<xsl:template match="autoIncludeSystem[autoincludesystem_info/@*]>
  <!-- code for elements with attributes (xsl:when) -->
</xsl:template>


<xsl:template match="autoIncludeSystem[not(autoincludesystem_info/@*)]>
  <!-- code for elements without attributes (xsl:otherwise) -->
</xsl:template>
原文链接:https://www.f2er.com/xml/293756.html

猜你在找的XML相关文章