显示与occurenceRefs对应的每个Occurence的第一个UserData元素的所有属性?

时间:2012-04-02 15:04:55

标签: xml xslt xpath

我有以下代码,我想显示每个Occurence对应于occurenceRefs的第一个UserData元素的所有属性?实际上我想以HTML格式显示它,我无法遍历属性并单独显示它们 在此先感谢.....

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" ?>
<!-- GENERATED BY: PLM XML SDK 7.0.2.173 -->
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
 schemaVersion="6" language="en-us" date="2012-03-23" languages="en-us" time="07:54:04" >
<Header id="id1" traverseRootRefs="#id7" transferContext="CRF_ITM_RPT_TMODE_INST"></Header>
<RevisionRule id="id2" name="Latest Working">
<Description>Latest Working else Latest Any Status</Description>
<ApplicationRef version="QQO9hJBI40bQ2C" application="Teamcenter" label="QQO9hJBI40bQ2C"></ApplicationRef></RevisionRule>
<ProductView id="id4" ruleRefs="#id2" rootRefs="id7" primaryOccurrenceRef="id7">
<ApplicationRef application="Teamcenter" label="BgE9Vysa40bQ2C/QQO9hJBI40bQ2C/AAAAAAAAAAAAAA/BOM"></ApplicationRef>
<UserData id="id3" type="TC Specific Properties">
<UserValue value="imprecise" title="BOM_precision_type"></UserValue></UserData>
<Occurrence id="id7" occurrenceRefs="id11 id15 ">
<ApplicationRef application="Teamcenter" label="BgE9Vysa40bQ2C/"></ApplicationRef>
<UserData id="id6">
<UserValue value="" title="rox9DesignItemID"></UserValue>
<UserValue value="" title="rox9CommrclDesignItemID"></UserValue>
<UserValue value="" title="rox9DesignRevision"></UserValue>
<UserValue value="" title="rox9CommrclDesignRevision"></UserValue></UserData>
<UserData id="id8" type="AttributesInContext">
<UserValue value="" title="AO_ID"></UserValue>
<UserValue value="" title="SequenceNumber"></UserValue>
<UserValue value="" title="OccurrenceName"></UserValue>
<UserValue value="" title="Quantity"></UserValue></UserData>
<Transform id="id5">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform></Occurrence>
<Occurrence id="id11" parentRef="#id7">
<ApplicationRef application="Teamcenter" label="BgE9Vysa40bQ2C/BsC9Vysa40bQ2C/"></ApplicationRef>
<UserData id="id10">
<UserValue value="" title="rox9DesignItemID"></UserValue>
<UserValue value="ROXD00216480" title="rox9CommrclDesignItemID"></UserValue>
<UserValue value="" title="rox9DesignRevision"></UserValue>
<UserValue value="A" title="rox9CommrclDesignRevision"></UserValue></UserData>
<UserData id="id12" type="AttributesInContext">
<UserValue value="" title="AO_ID"></UserValue>
<UserValue value="10" title="SequenceNumber"></UserValue>
<UserValue value="" title="OccurrenceName"></UserValue>
<UserValue value="" title="Quantity"></UserValue></UserData>
<Transform id="id9">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform></Occurrence>
<Occurrence id="id15" parentRef="#id7">
<ApplicationRef application="Teamcenter" label="BgE9Vysa40bQ2C/BsG9Vysa40bQ2C/"></ApplicationRef>
<UserData id="id14">
<UserValue value="ROXD00315587" title="rox9DesignItemID"></UserValue>
<UserValue value="" title="rox9CommrclDesignItemID"></UserValue>
<UserValue value="C" title="rox9DesignRevision"></UserValue>
<UserValue value="" title="rox9CommrclDesignRevision"></UserValue></UserData>
<UserData id="id16" type="AttributesInContext">
<UserValue value="" title="AO_ID"></UserValue>
<UserValue value="20" title="SequenceNumber"></UserValue>
<UserValue value="" title="OccurrenceName"></UserValue>
<UserValue value="" title="Quantity"></UserValue></UserData>
<Transform id="id13">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform></Occurrence>

我已经理解了很多并且能够获取和显示它们但是我希望它们显示如下所示,所以问题是我不知道如何单独循环它们或者我们可能必须使用模板并重复调用它们....... 任何帮助表示赞赏。请参阅上面的代码

提前致谢  所需的输出是:

rox9DesignItemID  rox9CommrclDesignItemID  rox9DesignRevision  rox9CommrclDesignRevision


                ROXD00216480                                        A 


 ROXD00315587                                 C

以下是上述XML文件的代码。我差不多完成了它,我在creCLext模板中的occid序列中得到了occurenceRefs,我通过显示它来验证它。问题是同一模板中UserValue的属性没有显示,我无法弄清楚问题是什么,xpath有什么问题吗?在creCLext模板中显示属性的正确Xpath是什么?

提前致谢

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

<xsl:output method="html" indent="yes"/>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
<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="roe1" select="$roe/@occurrenceRefs"/>
<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"/>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
<xsl:template match="/">
<html>
<head>
     <title>Global Teamcenter - BOM Report</title>
     <script type="text/javascript">
            function displayDate()
            {
             var d=new Date();
             var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
             var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
             document.write(monthname[d.getMonth()] + " ");
             document.write(d.getDate() + ", ");
             document.write(d.getFullYear() + " ");
             document.write(weekday[d.getDay()] + " ");
            }
      </script>
</head>
<body style="background-position: 21px 0px; font-size: 10pt; color: black; font-family: Verdana; background-color: white;" lang="en-us">
<div> </div>       
<div align="left"> </div>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
<div align="center">
<table style="table-layout: fixed; border-width: medium; border-style: none; border-color: -moz-use-text-color; font-size: 10pt; width: 653px; font-family: Verdana; border-collapse: collapse; word-wrap: break-word;" border="1" cellpadding="5">
    <colgroup>
        <col style="width: 271px;" width="271"></col>
        <col style="width: 24px;" width="24"></col>
        <col style="width: 358px;" width="358"></col>
    </colgroup>

<tbody valign="top"> 

<tr style="min-height: 42px;">
    <td colspan="3" style="border-width: 1pt 1pt 5pt; border-style: none none solid; border-color: rgb(153, 168, 172) rgb(153, 168, 172) rgb(81, 125, 191); color: rgb(235, 240, 249); background-color: rgb(30, 60, 123); text-align: left;" width="653">
        <h6 align="center" style="margin-top: 0px; font-weight: normal; margin-bottom: 0px; color: rgb(235, 240, 249);">
            <font face="Verdana" size="4">ISE GTc Monthly User Report</font>
        </h6>
    </td>
</tr>

<tr style="min-height: 42px;">
    <td colspan="3" style="border-width: 5pt 1pt 1pt; border-style: solid none none; border-color: rgb(81, 125, 191) rgb(153, 168, 172) rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249); text-align: left;" width="653">
        <div>
            <font face="Verdana" size="1">Generated by:</font>
        </div>
        <div>
            <span>
                <span title="Issue Title" id="L042502201095146C" style="border-right: 1pt none rgb(220, 220, 220); min-height: 18px; padding: 1px; border-width: 1pt; border-style: none; border-color: rgb(220, 220, 220); display: inline-block; margin: 1px; overflow: hidden; width: 100%; color: rgb(0, 0, 255); white-space: nowrap; text-overflow: ellipsis; background-color: rgb(255, 255, 255); text-align: left; word-wrap: normal;"> 
                  Atul Kumar
                </span>
            </span>
        </div>
    </td>
</tr>

<tr style="min-height: 42px;">
    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249); text-align: left;" width="271">
        <div>
            <font face="Verdana" size="1">Date:</font>
        </div>
        <div>
            <span>
                <span title="Opened By"  id="L042586E014BA9B4F" style="border-right: 1pt none rgb(220, 220, 220); min-height: 18px; padding: 1px; border-width: 1pt; border-style: none; border-color: rgb(220, 220, 220); display: inline-block; margin: 1px; overflow: hidden; width: 100%; color: rgb(0, 0, 255); white-space: nowrap; text-overflow: ellipsis; background-color: rgb(255, 255, 255); text-align: left; word-wrap: normal;">
                 <script type="text/javascript">
                  displayDate()
                 </script>
                </span>
            </span>
        </div>
    </td>
    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249);" width="24">
        <div>
            <font face="Verdana" size="2">   </font>
        </div>
    </td>
    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249); text-align: left;" width="358">
        <div>
            <font face="Verdana" size="1">Site Name:</font>
        </div>

        <div>
            <span>
                <span title="" id="L042587201D05A9D5" style="padding: 1px; display: inline-block; margin: 1px; overflow: hidden; width: 100%; color: rgb(0, 0, 255); white-space: normal; text-overflow: ellipsis; background-color: window; text-align: left; word-wrap: normal;">
                <xsl:value-of select="$site_name"/>
                </span>
            </span>
        </div>
    </td>   

</tr>

<tr style="min-height: 38px;">
    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249); text-align: left;" width="271">
        <div>
            <font face="Verdana" size="1">Author Licenses:</font>
        </div>
        <div>
        <span>
            <span title="Area Owner" id="L0425876018E022B2" style="padding: 1px; min-height: 18px; display: inline-block; margin: 1px; overflow: hidden; width: 100%; color: rgb(0, 0, 255); white-space: normal; text-overflow: ellipsis; background-color: rgb(255, 255, 255); text-align: left; word-wrap: normal;">
            <xsl:value-of select="count(//plm:UserValue[@title = 'license_level' and @value= '0' and @type='int'])"/>
            </span>
        </span>
        </div>
    </td>

    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249);" width="24">
        <div>
            <font face="Verdana" size="2">   </font>
        </div>
    </td>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
    <td style="border-width: 1pt; border-style: none; border-color: rgb(153, 168, 172); color: black; background-color: rgb(235, 240, 249); text-align: left;" width="358">
        <div>
            <font face="Verdana" size="1">Consumer Licenses:</font>
        </div>

        <div>
            <span>
                <span title="" id="L042587201D05A9D5" style="padding: 1px; display: inline-block; margin: 1px; overflow: hidden; width: 100%; color: rgb(0, 0, 255); white-space: normal; text-overflow: ellipsis; background-color: window; text-align: left; word-wrap: normal;">
                <xsl:value-of select="count(//plm:UserValue[@title = 'license_level' and @value= '1' and @type='int'])"/>
                </span>
            </span>
        </div>
    </td>   
</tr>
</tbody>
</table>
</div>
<div>
    <span title="" id="" style="padding: 1px; overflow-x: hidden; margin: 1px; width: 647px; text-overflow: ellipsis; word-wrap: break-word;">
    </span>
</div>

<div align="center">
    <table title="" style="table-layout: fixed; border-width: medium; border-style: none; border-color: -moz-use-text-color; font-size: 10pt; width: 651px; font-family: Verdana; border-collapse: collapse; word-wrap: break-word;" border="1">
        <colgroup>
            <col style="width: 200px;" width="200"></col>
            <col style="width: 160px;" width="160"></col>
            <col style="width: 100px;" width="100"></col>
            <col style="width: 185px;" width="185"></col>
        </colgroup>
    <tbody>
        <tr style="">
            <td style="color: black; background-color: rgb(235, 240, 249); border-width: 1pt; border-style: solid; border-color: rgb(81, 125, 191); vertical-align: top;" width="173">rox9DesignItemID</td>
            <td style="color: black; background-color: rgb(235, 240, 249); border-width: 1pt; border-style: solid; border-color: rgb(81, 125, 191); vertical-align: top;" width="253">rox9CommrclDesignItemID</td>
            <td style="color: black; background-color: rgb(235, 240, 249); border-width: 1pt; border-style: solid; border-color: rgb(81, 125, 191); vertical-align: top;" width="118">rox9DesignRevision</td>
            <td style="color: black; background-color: rgb(235, 240, 249); border-width: 1pt; border-style: solid; border-color: rgb(81, 125, 191); vertical-align: top;" width="173">rox9CommrclDesignRevision</td>    
        </tr>
    </tbody>
    <xsl:call-template name="createCL">
        <xsl:with-param name="occStr" select="$roe1"/>
    </xsl:call-template> 
    </table>
</div>
<br/>
</body>
</html>

</xsl:template>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
<xsl:template name="genData">
<xsl:param name="curPart"/>
<xsl:param name="occStr"/>
<xsl:param name="attStr"/>
</xsl:template>
<!-- inside createCL otherwise occStr <xsl:value-of select="$occStr"/> -->  
<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:call-template name="createCL">
                <xsl:with-param name="occStr" select="$occid"/>
            </xsl:call-template>

            <xsl:call-template name="createCL">
                <xsl:with-param name="occStr" select="substring-after($occStr,' ')"/>
            </xsl:call-template>
</xsl:when>
<xsl:otherwise>

        <xsl:call-template name="creCLext">
            <xsl:with-param name="occid" select="$occStr"/>
        </xsl:call-template>

</xsl:otherwise>

</xsl:choose>
</xsl:if>
</xsl:template>

<!-- Reference to the user element and user_id,status and license_level attribute  -->
<xsl:template name="creCLext">
<xsl:param name="occid"/>
    <!-- Reference to the user element and user_id,status and license_level attribute  -->
    <xsl:variable name="occname" select="/plm:PLMXML/plm:ProductView/plm:Occurence[@id=$occid]"/>
    <xsl:variable name="attribute1" select="$occname/plm:UserData[1]/plm:UserValue[1]/@title"/>
    <xsl:variable name="attribute2" select="$occname/plm:UserData[1]/plm:UserValue[2]/@title"/>
    <xsl:variable name="attribute3" select="$occname/plm:UserData[1]/plm:UserValue[3]/@value"/>
    <xsl:variable name="attribute4" select="$occname/plm:UserData[1]/plm:UserValue[4]/@value"/>
    <!-- Reference to the person element and last name attribute  -->             



   <!-- Displaying the values by row order -->
      <tr>
         <td>
         <xsl:value-of select="$attribute1"/></td>
         <td><xsl:value-of select="$attribute2"/></td>
         <td><xsl:value-of select="$attribute3"/>
         </td>
         <td><xsl:value-of select="$attribute4"/></td>
      </tr>           
</xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

我不确定'对应于occurenceRefs?'是什么意思。这是一个与每个UserData的第一个Occurrence匹配的XSL(XPath:plxml:Occurrence/plxml:UserData[1])并输出其所有属性(XPath:@*):

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

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="text()">
  </xsl:template>

  <xsl:template match="plxml:Occurrence/plxml:UserData[1]">
    <xsl:for-each select="@*">
      <p>
        <xsl:value-of select="concat(local-name(),'=',.)"/>
      </p>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

以下是输出每个UserValue而不是每个属性的相同XSL的变体:

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

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="text()">
  </xsl:template>

  <xsl:template match="plxml:Occurrence/plxml:UserData[1]">
    <xsl:for-each select="plxml:UserValue">
      <p>
        <xsl:value-of select="concat(@title,'=',@value)"/>
      </p>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

修改

修复模板如下:

  <xsl:template name="creCLext">
    <xsl:param name="occid"/>
    <!-- Reference to the user element and user_id,status and license_level attribute  -->
    <xsl:variable name="occname" select="/plm:PLMXML/plm:ProductView/plm:Occurrence[@id=$occid]"/>
    <xsl:variable name="attribute1" select="$occname/plm:UserData[1]/plm:UserValue[1]/@value"/>
    <xsl:variable name="attribute2" select="$occname/plm:UserData[1]/plm:UserValue[2]/@value"/>
    <xsl:variable name="attribute3" select="$occname/plm:UserData[1]/plm:UserValue[3]/@value"/>
    <xsl:variable name="attribute4" select="$occname/plm:UserData[1]/plm:UserValue[4]/@value"/>
    <!-- Reference to the person element and last name attribute  -->



    <!-- Displaying the values by row order -->
    <tr>
      <td>
        <xsl:value-of select="$attribute1"/>
      </td>
      <td>
        <xsl:value-of select="$attribute2"/>
      </td>
      <td>
        <xsl:value-of select="$attribute3"/>
      </td>
      <td>
        <xsl:value-of select="$attribute4"/>
      </td>
    </tr>
  </xsl:template>
相关问题