XSLT 2.0 如果条件 [英] XSLT 2.0 if condition
本文介绍了XSLT 2.0 如果条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要有关 XSLT 2.0 转换的帮助.
Need help on XSLT 2.0 transformation.
输入xml:
<Employee>
<Post>Manager</Post>
</Employee>
伪代码:
if(Employee/Post = 'Manager') then
Associate/High = 'Band'
else
Associate/Low = 'Band'
输出xml:
<Associate>
<High>Band</High>
</Associate>
<Associate>
<Low>Band</Low>
</Associate>
推荐答案
使用 xsl:element
动态构造一个元素.除此之外,你的伪代码已经很准确了.
Construct an element dynamically with xsl:element
. Other than that, your pseudo code is already pretty accurate.
XSLT 样式表
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="Employee">
<Associate>
<xsl:element name="{if (Post = 'Manager') then 'High' else 'Low'}">
<xsl:value-of select="'Band'"/>
</xsl:element>
</Associate>
</xsl:template>
</xsl:transform>
XML 输出
<Associate>
<High>Band</High>
</Associate>
这篇关于XSLT 2.0 如果条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文