Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xsl如何显示同一字段的所有属性_Xml_Xml Parsing_Xslt 1.0 - Fatal编程技术网

Xml 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

我有以下字段(f28),并希望显示所有包含数据的结果。 已经有模板来显示值,并且不显示value=null

我的xsl。。对于每个字段

 <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
      无效
    • 中间步骤(
      )是确保一切按正确顺序处理所必需的
    • 如果要手动确定输出顺序,可以在
      中使用
      ,也可以连续多次使用

    请为您的示例输入提供所需的输出XML(准确无误,请勿挥手),没有它,您的问题将模棱两可。编辑查询…谢谢!