Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
如何根据ID条目对.xml文件进行排序和合并节_Xml_Xslt - Fatal编程技术网

如何根据ID条目对.xml文件进行排序和合并节

如何根据ID条目对.xml文件进行排序和合并节,xml,xslt,Xml,Xslt,我有一个.xml文件,其中包含两组信息,我希望根据它们的ID值(1.2)相互匹配。例如,这个片段 <rule id="1.2"> <checker id="checker.id"> <description locale="en">description</description> </checker> </rule> <rule id="1.2"> &

我有一个.xml文件,其中包含两组信息,我希望根据它们的ID值(1.2)相互匹配。例如,这个片段

<rule id="1.2">
      <checker id="checker.id">
         <description locale="en">description</description>
      </checker>
</rule>

<rule id="1.2">
        <checker>
            <category locale="en">Advisory</category>
            <decidable locale="en">Yes</decidable>
        </checker>  
</rule>    

描述
咨询的
对
对于每个规则,我都有一个.xsl,将值添加到表条目中

<row>
    <entry>
        <xsl:value-of select="@id"/>                                                                    
    </entry>
    <entry>
        <xsl:for-each select="checker">
        <xsl:value-of select="category[@locale=$locale]"/>
        </xsl:for-each>
    </entry>
    <entry>
        <xsl:for-each select="checker">
        <xsl:value-of select="decidable[@locale=$locale]"/>
        </xsl:for-each>
    </entry>
    <entry>
        <xsl:for-each select="checker">
        <p>
        <codeph>
        <xsl:value-of select="@id"/></codeph><xsl:text>&#160;</xsl:text>
        <xsl:value-of select="description[@locale=$locale]"/>
        </p>
        </xsl:for-each>                                   
    </entry>                                    
</row>  


 

当前结果给出了这一点,但它创建了两个单独的行,即使ID相同。我该怎么做才能使具有相同ID的信息位于同一行中

<row>
    <entry>1.2</entry>
    <entry>Advisory</entry>
    <entry>Yes</entry>
    <entry>
    <p>
    <codeph/></p>
    </entry>
</row>
<row>
    <entry>1.2</entry>
    <entry/>
    <entry/>
    <entry>
    <p>
    <codeph>checker.id</codeph>description</p>
    </entry>
</row>

1.2
咨询的
对

1.2 checker.iddescription

预期结果:

<row>
    <entry>1.2</entry>
    <entry>Advisory</entry>
    <entry>Yes</entry>
    <entry>
    <p><codeph>checker.id</codeph>description</p>
    </entry>
</row>

1.2
咨询的
对
checker.iddescription


这是所谓的 以下XSLT选择所有
中排序的
的第一个匹配项,然后通过将
/
运算符与谓词一起应用,将所有
与相同的
@id
匹配,从而编译所需的结果

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:key name="kSorted" match="rule" use="@id" />
  <xsl:variable name="locale" select="'en'" />

    <xsl:template match="/root">
      <xsl:apply-templates select="rule[generate-id() = generate-id(key('kSorted',@id)[1])]">
        <xsl:sort select="@id" />
      </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="rule">
      <xsl:variable name="thisID" select="@id" />
      <row>
        <entry><xsl:value-of select="@id"/></entry>
        <entry><xsl:value-of select="//rule[@id = $thisID]//category[@locale=$locale]"/></entry>
        <entry><xsl:value-of select="//rule[@id = $thisID]//decidable[@locale=$locale]"/></entry>
        <entry>
          <p>
            <codeph><xsl:value-of select="checker/@id"/></codeph><xsl:text>&#160;</xsl:text>
            <xsl:value-of select="checker/*[@locale=$locale][1]"/>
          </p>
        </entry>                                    
      </row> 
    </xsl:template>

</xsl:stylesheet>


 


这是所谓的 以下XSLT选择所有
中排序的
的第一个匹配项,然后通过将
/
运算符与谓词一起应用,将所有
与相同的
@id
匹配,从而编译所需的结果

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:key name="kSorted" match="rule" use="@id" />
  <xsl:variable name="locale" select="'en'" />

    <xsl:template match="/root">
      <xsl:apply-templates select="rule[generate-id() = generate-id(key('kSorted',@id)[1])]">
        <xsl:sort select="@id" />
      </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="rule">
      <xsl:variable name="thisID" select="@id" />
      <row>
        <entry><xsl:value-of select="@id"/></entry>
        <entry><xsl:value-of select="//rule[@id = $thisID]//category[@locale=$locale]"/></entry>
        <entry><xsl:value-of select="//rule[@id = $thisID]//decidable[@locale=$locale]"/></entry>
        <entry>
          <p>
            <codeph><xsl:value-of select="checker/@id"/></codeph><xsl:text>&#160;</xsl:text>
            <xsl:value-of select="checker/*[@locale=$locale][1]"/>
          </p>
        </entry>                                    
      </row> 
    </xsl:template>

</xsl:stylesheet>


 


使用所需结果编辑使用所需结果编辑