如何将属性值与另一个属性匹配

  • 本文关键字:属性 另一个 xslt-1.0
  • 更新时间 :
  • 英文 :


在XML文件中,历史元素包含两个MS_ID元素。我想在" ms_on"值中的属性中的文章_set/artical匹配" 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>

这个问题有些混乱,因为提供的XML没有articleauthor数据。

专注于您的特定问题:

我想在" ms_on"属性中匹配article_set/artic " ms_no"的历史记录/ms_id属性

解决交叉引用的最佳方法是使用。考虑以下样式表:

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>

相关内容

  • 没有找到相关文章

最新更新