Xml xsl如何显示同一字段的所有属性
我有以下字段(f28),并希望显示所有包含数据的结果。 已经有模板来显示值,并且不显示value=null 我的xsl。。对于每个字段Xml xsl如何显示同一字段的所有属性,xml,xml-parsing,xslt-1.0,Xml,Xml Parsing,Xslt 1.0,我有以下字段(f28),并希望显示所有包含数据的结果。 已经有模板来显示值,并且不显示value=null 我的xsl。。对于每个字段 <xsl:template match="f28"> <xsl:choose> <xsl:when test="ROW/@f1 !='NULL'"> <xsl:element name="hasTestDegree" namespace="{namespace-uri()}#"&g
<xsl:template match="f28">
<xsl:choose>
<xsl:when test="ROW/@f1 !='NULL'">
<xsl:element name="hasTestDegree" namespace="{namespace-uri()}#">
<xsl:value-of select='ROW/@f1'/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>
我的XML:
<f28>
<ROW f1='FULL' f2='NULL' f3='NULL' f4='NULL' f5='not certain' f6='BRCA1' f7='NULL'/>
<ROW f1='FULL' f2='NULL' f3='NULL' f4='NULL' f5='no mutation' f6='BRCA2' f7='NULL'/>
<ROW f1='FULL' f2='NULL' f3='NULL' f4='NULL' f5='NULL' f6='p53' f7='NULL'/>
</f28>
我希望得到以下结果:
<hasTestDegree>FULL</hasTestDegree>
<hasTestResult>not certain</hasTestResult>
<hasTestType>BRCA1</hasTestType>`
<hasTestDegree>FULL</hasTestDegree>
<hasTestResult>no mutation</hasTestResult>
<hasTestType>BRCA2</hasTestType>`
<hasTestDegree>FULL</hasTestDegree>
<hasTestType>p53</hasTestType>`
FULL
不确定
BRCA1`
满满的
无突变
BRCA2`
满满的
p53`
<xsl:template match="f28">
<xsl:apply-templates select="ROW" />
</xsl:template>
<xsl:template match="ROW">
<xsl:apply-templates select="@*">
<xsl:sort select="name()" />
</xsl:apply-templates>
</xsl:template>
<!-- @f1 becomes <hasTestDegree> -->
<xsl:template match="f28//@f1">
<hasTestDegree>
<xsl:value-of select="." />
</hasTestDegree>
</xsl:template>
<!-- add more templates for the other attributes... -->
<!-- any attribute with a value of 'NULL' is not output -->
<xsl:template match="@*[. = 'NULL']" />
注释
- 似乎没有必要使用
在您的情况下,只需写出要创建的元素即可 - 我的解决方案依赖于匹配特异性。匹配表达式
对@*[.='NULL']
属性的'NULL'
无效f28//@f1
- 中间步骤(
)是确保一切按正确顺序处理所必需的 - 如果要手动确定输出顺序,可以在
中使用
,也可以连续多次使用