2016-12-30 94 views
0

在xml文件中,歷史元素包含兩個ms_id元素。我想將「ms_on」值屬性中的article_set/article與「ms_no」的歷史/ ms_id屬性相匹配並在瀏覽器中查看。如何將屬性值與其他屬性匹配

XML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<!--s1.dtd v4.20--> 
<!DOCTYPE article_set SYSTEM "s1.dtd"> 
<article_set dtd_version="4.20"> 
<article export_date="2016-12-27 00:00:00.0" lang="EN" ms_no="EMI-2016-1600.R1" rev="1"> 
<history> 
<ms_id ms_no="EMI-2016-1600.R1"> 
<rev_id>1</rev_id> 
<submitted_date> 
<year>2016</year> 
<month>12</month> 
<day>23</day> 
<hour>13</hour> 
<minute>02</minute> 
<second>36</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</submitted_date> 
<received_date> 
<year>2016</year> 
<month>10</month> 
<day>17</day> 
<hour>05</hour> 
<minute>59</minute> 
<second>50</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</received_date> 
<received_date_resub> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</received_date_resub> 
<revised_date> 
<year>2016</year> 
<month>12</month> 
<day>23</day> 
<hour>13</hour> 
<minute>02</minute> 
<second>36</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</revised_date> 
<decision_date> 
<year>2016</year> 
<month>12</month> 
<day>27</day> 
<hour>03</hour> 
<minute>44</minute> 
<second>07</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</decision_date>Kindly check and do the needful. 
<approval_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</approval_date> 
<author_returned_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</author_returned_date> 
<most_recent_decision_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</most_recent_decision_date> 
<transmission_date> 
<year>2016</year> 
<month>10</month> 
<day>17</day> 
<hour>05</hour> 
<minute>59</minute> 
<second>50</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</transmission_date> 
<web_publish_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</web_publish_date> 
<task name="Forward to Admin" task_id="50995" type="forward document"> 
<status doc_task_id="206939948" event_date="2016-12-23T01:02:37" s1_staff="false" user_id="4799597" user_role="Admin">completed</status> 
<assigned date="2016-12-23T01:02:37" role="Admin" user_id="4799597"/> 
</task> 
<task name="Branch" task_id="51104" type="branch"> 
<status doc_task_id="206939949" event_date="2016-12-23T01:02:37" s1_staff="false" user_id="0" user_role="SYSTEM ROLE">completed</status> 
</task> 
<task name="Forward to Juan Luis Ramos" task_id="173153" type="forward document"> 
<status doc_task_id="206939950" event_date="2016-12-23T01:02:37" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
<assigned date="2016-12-23T01:02:37" role="Editor" user_id="6603746"/> 
</task> 
<task name="ED Checklist" task_id="51108" type="manuscript checklist"> 
<status doc_task_id="206939951" event_date="2016-12-24T03:20:35" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
</task> 
<task name="ED Decision" task_id="50993" type="decision"> 
<status doc_task_id="206939952" event_date="2016-12-27T03:44:07" s1_staff="false" user_id="6603746" user_role="Editor">abandoned</status> 
</task> 
<task name="ED Pick Reviewers" task_id="50987" type="pick2"> 
<status doc_task_id="206961933" event_date="2016-12-26T12:04:53" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
</task> 
<task name="ED Invite Reviewers" task_id="146873" type="invite"> 
<status doc_task_id="206961934" event_date="2016-12-26T12:04:53" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
</task> 
<task name="ED Decision" task_id="50993" type="decision"> 
<status doc_task_id="207034905" event_date="2016-12-27T03:44:07" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
<decision decision_name="Accept" decision_type="Accept"/> 
</task> 
<task name="Production Checklist" task_id="73019" type="production checklilst"> 
<status doc_task_id="207063310" event_date="2016-12-27T03:44:37" s1_staff="false" user_id="6603746" user_role="Editor">completed</status> 
</task> 
<task name="Production Checklist" task_id="73019" type="production checklilst"> 
<status doc_task_id="207063311" event_date="2016-12-27T03:44:37" s1_staff="false" user_id="0" user_role="">abandoned</status> 
</task> 
<task name="Branch on Batch Destination" task_id="194394" type="branch"> 
<status doc_task_id="207063343" event_date="2016-12-27T03:44:37" s1_staff="false" user_id="0" user_role="SYSTEM ROLE">completed</status> 
</task> 
<task name="Assign to Batch EMI" task_id="51001" type="assign to batch"> 
<status doc_task_id="207063344" event_date="2016-12-27T03:44:37" s1_staff="false" user_id="0" user_role="Production Editor">processing</status> 
</task> 
</ms_id> 
<ms_id ms_no="EMI-2016-1600"> 
<rev_id>0</rev_id> 
<submitted_date> 
<year>2016</year> 
<month>10</month> 
<day>17</day> 
<hour>05</hour> 
<minute>59</minute> 
<second>50</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</submitted_date> 
<received_date> 
<year>2016</year> 
<month>10</month> 
<day>17</day> 
<hour>05</hour> 
<minute>59</minute> 
<second>50</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</received_date> 
<received_date_resub> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</received_date_resub> 
<revised_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</revised_date> 
<decision_date> 
<year>2016</year> 
<month>11</month> 
<day>20</day> 
<hour>16</hour> 
<minute>51</minute> 
<second>51</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</decision_date> 
<approval_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</approval_date> 
<author_returned_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</author_returned_date> 
<most_recent_decision_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</most_recent_decision_date> 
<transmission_date> 
<year>2016</year> 
<month>10</month> 
<day>17</day> 
<hour>05</hour> 
<minute>59</minute> 
<second>50</second> 
<time_zone>(GMT-05:00) Eastern Time (US &amp; Canada)</time_zone> 
</transmission_date> 
<web_publish_date> 
<year/> 
<month/> 
<day/> 
<hour/> 
<minute/> 
<second/> 
<time_zone/> 
</web_publish_date> 
</ms_id> 
</history> 
</article> 
</article_set> 

XSLT文件:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
<html> 
<head> 
<style type="text/css"> 
</style> 
</head> 
<body style="font-family:Arial;"> 
<h2>Wiley Meta Information</h2> 
<xsl:for-each select="article_set/article"> 
<p><b>Article Title:</b>&#x2003;<xsl:value-of select="article_title"/></p> 
<xsl:for-each select="author_list/author"> 
<p><b>Authors:</b>&#x2003;<span style="color:blue;font-weight:bold;" title="salutation"><xsl:value-of select="salutation"/></span>&#x2003;<span style="color:green;font-weight:bold;" title="first name"><xsl:value-of select="first_name"/></span>&#x2003;<span style="color:skyblue;font-weight:bold;" title="middle name"><xsl:value-of select="middle_name"/></span>&#x2003;<span style="color:brown;font-weight:bold;" title="last name"><xsl:value-of select="last_name"/></span></p> 
<p><b>ORC ID:</b>&#x2003;<xsl:value-of select="orcid"/></p> 
</xsl:for-each> 
<p><b>Corresponding Author:</b>&#x2003;<xsl:value-of select="corresponding_author"/></p> 
<xsl:for-each select="history/ms_id/submitted_date"> 
<p><b>Accepted Date:</b>&#x2003;<xsl:value-of select="day"/>-<xsl:value-of select="month"/>-<xsl:value-of select="year"/></p> 
</xsl:for-each> 
<xsl:for-each select="history/ms_id/received_date"> 
<p><b>Received Date:</b>&#x2003;<xsl:value-of select="day"/>-<xsl:value-of select="month"/>-<xsl:value-of select="year"/></p> 
</xsl:for-each> 
<xsl:for-each select="history/ms_id/revised_date"> 
<p><b>Revised Date:</b>&#x2003;<xsl:value-of select="day"/>-<xsl:value-of select="month"/>-<xsl:value-of select="year"/></p> 
</xsl:for-each></xsl:for-each> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 
+1

請發表您的代碼** **代碼。考慮將示例降低到顯示問題所需的最小值,並顯示預期結果。 –

回答

0

的問題是有點混亂,因爲提供的XML沒有articleauthor數據。

專注於你的具體的問題: 「ms_no」

最好

我想在 「ms_on」 值的屬性article_set /條匹配 歷史/ ms_id屬性解決交叉引用的方法是使用key。請看下面的樣式表:

XSLT 1.0

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

<xsl:key name="rev" match="ms_id" use="@ms_no" /> 

<xsl:template match="/"> 
    <html> 
     <body> 
      <xsl:for-each select="article_set/article"> 
       <p>Article information goes here</p> 
       <p>Author/s information goes here</p> 
       <!-- get data about revision dates --> 
       <xsl:apply-templates select="key('rev', @ms_no)"/> 
      </xsl:for-each> 
     </body> 
    </html> 
</xsl:template> 

<xsl:template match="ms_id"> 
    <xsl:for-each select="submitted_date"> 
     <p> 
      <b>Accepted Date:</b> 
      <xsl:text>&#x2003;</xsl:text> 
      <xsl:value-of select="concat(day, '-', month, '-', year)"/> 
     </p> 
    </xsl:for-each> 
    <xsl:for-each select="received_date"> 
     <p> 
      <b>Received Date:</b> 
      <xsl:text>&#x2003;</xsl:text> 
      <xsl:value-of select="concat(day, '-', month, '-', year)"/> 
     </p> 
    </xsl:for-each> 
    <xsl:for-each select="revised_date"> 
     <p> 
      <b>Revised Date:</b> 
      <xsl:text>&#x2003;</xsl:text> 
      <xsl:value-of select="concat(day, '-', month, '-', year)"/> 
     </p> 
    </xsl:for-each> 
</xsl:template> 

</xsl:stylesheet> 

應用到你的輸入例子,結果將是:

<html> 
<body> 
<p>Article information goes here</p> 
<p>Author/s information goes here</p> 
<p> 
<b>Accepted Date:</b>&emsp;23-12-2016</p> 
<p> 
<b>Received Date:</b>&emsp;17-10-2016</p> 
<p> 
<b>Revised Date:</b>&emsp;23-12-2016</p> 
</body> 
</html> 
+0

非常感謝你 –

+0

如何通過接受答案來關閉它? –

+0

http://meta.stackexchange.com/a/5235/245750 –

相關問題