Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 xslt中的排序?_Xml_Xslt_Xpath - Fatal编程技术网

Xml xslt中的排序?

Xml xslt中的排序?,xml,xslt,xpath,Xml,Xslt,Xpath,我有一个下面的代码,它从相应的plmxml文件中获取记录并显示记录。我正在以作者身份显示许可证状态0,以消费者身份显示许可证状态1。我想要的是在显示输出时将许可证状态排序为作者和消费者?我将它显示为html。我怎么做 提前谢谢 <?xml version="1.0"?> <!-- Filename: default_xml_template.xsl Default xsl template file for XML report --> &

我有一个下面的代码,它从相应的plmxml文件中获取记录并显示记录。我正在以作者身份显示许可证状态0,以消费者身份显示许可证状态1。我想要的是在显示输出时将许可证状态排序为作者和消费者?我将它显示为html。我怎么做

提前谢谢

    <?xml version="1.0"?>

<!--

    Filename: default_xml_template.xsl

    Default xsl template file for XML report

-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
           xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema">

<!--  Defining output as HTML -->
<xsl:output method="html" indent="yes"/>

<!--  Defining Global Variables 

       These are defined to avoid redundancy and use variables throughout the xsl document
--> 
<xsl:variable name="trvrootref" select="/plm:PLMXML/plm:Header/@traverseRootRefs"/>
<xsl:variable name="roid" select="substring-after($trvrootref,'#')"/>
<xsl:variable name="roe" select="/plm:PLMXML/plm:ProductView/plm:Occurrence[@id=$roid]"/>
<xsl:variable name="rprid" select="substring-after($roe/@instancedRef,'#')"/>
<xsl:variable name="root" select="/plm:PLMXML/plm:ProductRevision[@id=$rprid]"/>
<!-- Reference to the Site element and last name attribute  -->    
<xsl:variable name="site" select="/plm:PLMXML/plm:Site"/>   
<xsl:variable name="site_name" select="$site/@name"/>

<!--  The match attribute is used to associate a template with an XML element. 

       The match attribute can also be used to define a template for the entire XML document. 

       The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).
--> 
<xsl:template match="/">

<!-- 

       HTML to define the structure and presentation of the output report to be published      

-->
<html>
<head>
     <title>Global Teamcenter - Employee Information</title>


<!-- 
         Calling the createCL template , passing parameter occStr as trvrootref variable
-->
    <xsl:call-template name="createCL">
        <xsl:with-param name="occStr" select="$trvrootref"/>
    </xsl:call-template> 
    </table>
</div>
<br/>
</body>
</html>

</xsl:template>


<!-- Defining createCL template --> 
<xsl:template name="createCL">
<xsl:param name="occStr"/>
    <xsl:if test="$occStr!=''">
    <xsl:choose>
        <xsl:when test="contains($occStr,' ')">
            <xsl:variable name="occid" select="substring-before($occStr,' ')"/>
            <xsl:variable name="newid" select="substring-after($occid,'#')"/>
                <xsl:call-template name="createCL">
                <xsl:with-param name="occStr" select="$newid"/>
                </xsl:call-template>
                <xsl:call-template name="createCL">
                <xsl:with-param name="occStr" select="substring-after($occStr,' ')"/>
                </xsl:call-template>
        </xsl:when>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->      
        <xsl:otherwise>
        <xsl:choose>
         <xsl:when test="contains($occStr,'#')">
            <xsl:variable name="newid" select="substring-after($occStr,'#')"/>
<!-- 
         Calling the creCLext template , passing parameter occid as newid variable
-->
                <xsl:call-template name="creCLext">
                <xsl:with-param name="occid" select="$newid"/>
            </xsl:call-template>                
         </xsl:when>
             <xsl:otherwise>
<!-- 
         Calling the creCLext template , passing parameter occid as occStr variable
-->
                <xsl:call-template name="creCLext">
                    <xsl:with-param name="occid" select="$occStr"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        </xsl:otherwise>
    </xsl:choose>
    </xsl:if>
</xsl:template>

<!-- Defining creCLext template -->
<xsl:template name="creCLext">
<xsl:param name="occid"/>

<!-- Reference to the user element and user_id,status and license_level attribute  -->

    <xsl:variable name="user" select="/plm:PLMXML/plm:User[@id=$occid]"/>
    <xsl:variable name="per_ref" select="substring-after($user/@personRef,'#')" />
    <xsl:variable name="user_id" select="$user/@userId" />
    <xsl:variable name="license_level" select="$user/plm:UserData/plm:UserValue[3]/@value"/>
    <xsl:variable name="last_login_time" select="$user/plm:UserData/plm:UserValue[4]/@value"/>

<!-- Reference to the person element and last name attribute  -->

    <xsl:variable name="person" select="/plm:PLMXML/plm:Person[@id=$per_ref]"/>         
    <xsl:variable name="person_l" select="$person/@lastName"/>


   <!-- Displaying the values by row order -->
      <tr>
         <td>
         <xsl:value-of select="$person_l"/></td>
         <td><xsl:value-of select="$user_id"/></td>
         <td><xsl:choose>
              <xsl:when test="$license_level=0">Author</xsl:when> <!-- Converting the output to string value -->
              <xsl:otherwise>Consumer</xsl:otherwise>
             </xsl:choose>
         </td>
         <td><xsl:value-of select="$last_login_time"/></td>
      </tr>           
</xsl:template>
</xsl:stylesheet>

全球团队中心-员工信息

作者 消费者
看一看。这里有一个很好的使用方法。

谢谢@werner,但我已经读过了,它说我们可以在或中使用sort。虽然我想在内部排序,而不看XML源代码,但很难解释排序应该放在哪里。在源文档的某个地方,会有一组您想要排序的元素。样式表中的某个地方将有一个xsl:for-each或xsl:apply模板,用于处理该组元素。xsl:for-each或xsl:apply模板是xsl:sort需要使用的地方。@michealkay,我已经附加了上面的xslt代码。由于函数被重复调用,因此没有使用xsl:for-each和xsl:apply模板。我可以在显示时对许可证状态进行排序吗?此代码的基本问题是它不使用未命名的模板,相应地,
——所描述的“问题”非常简单,当模板被适当使用时,甚至不需要排序。我强烈建议您阅读一本关于XSLT和XPath的好书,在开始编写任何XSLT转换之前,至少要掌握基本知识。XSLT不同于C、Java、C#或迄今为止您所使用的任何语言——它需要“范式转换”,而您显然还没有通过这一点。谢谢@DimitreNovatchev,是的,我是XSLT的新手,只是满足了一个小的转换需求。我几乎完成了它,我需要在它显示之前进行整理。在xslt代码中不进行重大更改的情况下,是否可以按元素的方式进行排序?