Как преобразовать все один и тот же элемент в узле - PullRequest
0 голосов
/ 01 июля 2018

В приведенном ниже XML-файле содержится много авторских элементов. Я упомянул в xslt и отображаю только первый элемент. Я хочу показать все авторские элементы. Просьба указать, что код xslt для элемента, которого нет в тексте, будет отображаться в браузере.

XML-код:

<?xml version="1.0" encoding="US-ASCII" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="view.xsl"?>
<!DOCTYPE WileyML3G [
<!ENTITY % wileyml3g.ent SYSTEM "http://v.wiley.com:3535/dtds/wileyml3g/wiley.ent">
%wileyml3g.ent;
]>
<bibliography xml:id="aic16349-bibl-0001" style="numbered" cited="no">
<title type="main">REFERENCE<!--<QUERY xml:id="Q2"><p>References "3&#x2013;35" were not cited anywhere in the text. Please provide a citation. Alternatively, delete the items from the list.</p></QUERY>--></title>
<bib xml:id="aic16349-bib-0001">
<citation type="journal" xml:id="aic16349-cit-0001"><!--<QUERY xml:id="Q3"><p>Reference "1"  is not cited in the text. Please indicate where it should be cited; or delete from the reference list.</p></QUERY>-->
<author><familyName>Deer</familyName> <givenNames>TR</givenNames></author>, <author><familyName>Provenzano</familyName> <givenNames>DA</givenNames></author>, <author><familyName>Hanes</familyName> <givenNames>M</givenNames></author>, et al. <articleTitle>The Neurostimulation Appropriateness Consensus Committee (NACC) Recommendations for Infection Prevention and Management</articleTitle>. <journalTitle>Neuromodulation.</journalTitle> <pubYear year="2017">2017</pubYear>;<vol>20</vol>(<issue>1</issue>):<pageFirst>31</pageFirst>&#x2010;<pageLast>50</pageLast>.</citation>
</bib>

XSLT-код:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>HTML VIEW</h1>
<table border="1" cellpadding="10px">
<tr>
<th>Authors</th>
<th>Year</th>
<th>Article_Title</th>
<th>Journal_Title</th>
<th>Volume</th>
<th>Issue</th>
<th>First_Page</th>
<th>Last_Page</th>
</tr>
<xsl:for-each select="bibliography/bib/citation">
<tr>
<td><span style="background-color:skyblue;"><xsl:value-of select="author"/></span>, </td>
<td><xsl:value-of select="pubYear"/></td>
<td width="75%"><xsl:value-of select="articleTitle"/></td>
<td width="25%"><xsl:value-of select="journalTitle"/></td>
<td><xsl:value-of select="vol"/></td>
<td><xsl:value-of select="issue"/></td>
<td><xsl:value-of select="pageFirst"/></td>
<td><xsl:value-of select="pageLast"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Ответы [ 2 ]

0 голосов
/ 02 июля 2018

В качестве предложения @Martin, если вы действительно хотите использовать 1.0, вам нужно выбрать для каждого автора, например:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
                <h1>HTML VIEW</h1>
                <table border="1" cellpadding="10px">
                    <tr>
                        <th>Authors</th>
                        <th>Year</th>
                        <th>Article_Title</th>
                        <th>Journal_Title</th>
                        <th>Volume</th>
                        <th>Issue</th>
                        <th>First_Page</th>
                        <th>Last_Page</th>
                    </tr>
                    <xsl:for-each select="bibliography/bib/citation">
                        <tr>
                            <td>
                                <span style="background-color:skyblue;">
                                    <xsl:for-each select="author">
                                        <xsl:value-of select="."/>
                                        <xsl:if test="following-sibling::author"><xsl:text>, </xsl:text></xsl:if>
                                    </xsl:for-each>
                                </span>
                            </td>
                            <td><xsl:value-of select="pubYear"/></td>
                            <td width="75%"><xsl:value-of select="articleTitle"/></td>
                            <td width="25%"><xsl:value-of select="journalTitle"/></td>
                            <td><xsl:value-of select="vol"/></td>
                            <td><xsl:value-of select="issue"/></td>
                            <td><xsl:value-of select="pageFirst"/></td>
                            <td><xsl:value-of select="pageLast"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Или это будет сделано очень просто при работе с 2.0, как:

  1. Необходимо изменить версию XSLT с 1.0 на 2.0
  2. Используйте @seperator с , в значении автора.

    HTML VIEW

    Авторы Год Название статьи Journal_Title объем вопрос Первая страница Последняя страница
0 голосов
/ 01 июля 2018

Вы пометили вопрос как XSLT 2.0, и если вы действительно используете процессор XSLT 2.0 и используете version="2.0" в своей таблице стилей, тогда <xsl:value-of select="author"/> выведет все выбранные author дочерние элементы, и вы даже можете использовать <xsl:value-of select="author" separator=", "/> для разделите разных авторов на ,. Если вы используете XSLT 1.0, тогда используйте <xsl:appy-templates select="author"/> и <xsl:template match="author"><xsl:if test="position() > 1">, </xsl:if></xsl:value-of select="."/></xsl:template> или xsl:for-each, если вы предпочитаете это.

...