XSL if else 条件 [英] XSL if else condition
问题描述
我有一个要求,我希望使用 if else 语句来检查节点是否具有属性或只有字符串.
I have a requirement where I'd like to have if else statement to check whether a node has attributes or it has just string.
例如:节点的 1 个具有 0 文件找到
,另一个节点具有诸如 <autoincludesystem_info mdate='08/23/2011' mtime='09 的属性:51'ampm='PM'filesize='64'filename='AFP_p.tgp'/>
Eg: 1 of the node has 0 File(s) found
and the other has attribs such as <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='<DIR>' 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>
我如何确定节点是否只有字符串或属性,并基于此我可以分别获得 String
或 attrib 值
的值.
How would i identify if a node has just strings or attribs and based on that I can get the values either String
or attrib values
respectively.
推荐答案
您可以将整个 xsl:choose
指令替换为:
You can replace your whole xsl:choose
instruction with:
<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>
这篇关于XSL if else 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!