xslt - XSL:组合两个应用模板的输出并对它们进行排序
问题描述
亲爱的,目前我正在 WORD 中建立一个自定义引用样式,我想为参考书目的输出实现以下目标:
- 书籍部分应由各自的作者展示(BookSection)
- 书作者应在参考书目中显示为额外条目
- 两者的输出都应该归类到一个列表中!
我已经做到了,通过这样做,两部分条目将显示在参考书目中:
<xsl:template match="b:Bibliography">
<html xmlns="https://www.w3.org/TR/REC-html40">
<body>
<xsl:variable name="Literatur">
<xsl:apply-templates select ="b:Source[b:SourceType = 'BookSection'] | b:Source[b:SourceType = 'Book'] | b:Source[b:SourceType = 'ArticleInAPeriodical']" />
<xsl:apply-templates select ="b:Source[b:SourceType = 'BookSection']" mode="ExtraBookAuthorEntry" />
</xsl:variable>
<xsl:copy-of select="$Literatur"/>
<span style="font-size: 12pt; font-family: 'TimesNewRoman'; font-weight: bold;">
<xsl:text>Internetquellen</xsl:text>
</span>
<xsl:apply-templates select = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']">
<xsl:sort select="b:Tag" order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
现在第一个 apply-templates 的条目将可见,在此下方将有带有下一个 apply-tempates 的额外部分。
不过,我只想对变量“Literatur”中的两个应用模板进行排序
我怎样才能执行这种排序?你能帮我吗?
谢谢西蒙
- - 编辑 - -
我正在使用这段代码:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
xmlns:t="http://www.microsoft.com/temp">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="*" mode="outputHtml2">
<xsl:apply-templates mode="outputHtml"/>
</xsl:template>
<!--Match the root element, and dispatch to its children-->
<xsl:template match="/">
<xsl:apply-templates select="*" />
<xsl:choose>
<xsl:when test="b:Version">
<xsl:text>2020.10.23</xsl:text>
</xsl:when>
<xsl:when test="b:OfficeStyleKey">
<xsl:text>FOM Literatur</xsl:text>
</xsl:when>
<xsl:when test="b:XslVersion">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="b:StyleNameLocalized">
<xsl:choose>
<xsl:when test="b:StyleNameLocalized/b:Lcid='1033'">
<xsl:text>FOM Literatur</xsl:text>
</xsl:when>
<xsl:when test="b:StyleNameLocalized/b:Lcid='2070'">
<xsl:text>FOM Literatur</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
<!--<xsl:variable name="book_Title">
<xsl:value-of select="(b:Title)" />
</xsl:variable>-->
</xsl:template>
<xsl:template match="b:GetImportantFields[b:SourceType = 'Book']">
<b:ImportantFields>
<b:ImportantField>
<xsl:text>b:Author/b:Author/b:NameList</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Title</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:ShortTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Publisher</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:City</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Edition</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Year</xsl:text>
</b:ImportantField>
</b:ImportantFields>
</xsl:template>
<xsl:template match="b:GetImportantFields[b:SourceType = 'BookSection']">
<b:ImportantFields>
<b:ImportantField>
<!--AUTOR (Kurztitel, Jahr): Titel, in: Hrsg (Hrsg.), Buchtitel, Jahr, S. 277 - 299 -->
<xsl:text>b:Author/b:Author/b:NameList</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Title</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:ShortTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:BookTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Author/b:BookAuthor/b:NameList</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Publisher</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:City</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Edition</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Year</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Pages</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Comments</xsl:text>
</b:ImportantField>
</b:ImportantFields>
</xsl:template>
<!-- Artikel in einer Zeitschrift -->
<xsl:template match="b:GetImportantFields[b:SourceType = 'ArticleInAPeriodical']">
<b:ImportantFields>
<b:ImportantField>
<xsl:text>b:Author/b:Author/b:NameList</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Title</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:ShortTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:PeriodicalTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Volume</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Issue</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Year</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Pages</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Comments</xsl:text>
</b:ImportantField>
</b:ImportantFields>
</xsl:template>
<xsl:template match="b:GetImportantFields[b:SourceType = 'InternetSite']">
<b:ImportantFields>
<b:ImportantField>
<xsl:text>b:Author/b:Author/b:NameList</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Title</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:ShortTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:InternetSiteTitle</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Year</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Month</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:Day</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:YearAccessed</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:MonthAccessed</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:DayAccessed</xsl:text>
</b:ImportantField>
<b:ImportantField>
<xsl:text>b:URL</xsl:text>
</b:ImportantField>
</b:ImportantFields>
</xsl:template>
<!--### Abschnitt 2: Hier wird festgelegt, wie die einzelnen Quellen im Literaturverzeichnis
ausgegeben werden sollen. Hier sind noch nicht alle Arten von Quellen eingetragen.
Ggf. müssen die entsprechenden Quellenarten noch hinzugefügt werden.###-->
<xsl:template match = "b:Source[b:SourceType = 'Book'] | b:Source[b:SourceType = 'Report'] | b:Source[b:SourceType = 'ElectronicSource']">
<p>
<i> <!--Autorenliste-->
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
</i>
<xsl:text> (</xsl:text>
<xsl:value-of select = "b:ShortTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>): </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text>, </xsl:text>
<xsl:if test="b:Edition != ''">
<xsl:value-of select = "b:Edition"/>
<xsl:text>. Aufl., </xsl:text>
</xsl:if>
<xsl:value-of select = "b:City"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="b:Publisher"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
</p>
<!-- <p style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">
<span style="font-weight: bold; ">
<xsl:text>[</xsl:text>
<xsl:value-of select = "b:Tag"/>
<xsl:text>] </xsl:text>
</span> -->
<!--Autorenliste-->
<!-- <xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
<xsl:text>: </xsl:text> -->
<!--Titel-->
<!-- <xsl:value-of select = "b:Title"/> -->
<!--Datum-->
<!-- <xsl:text> (</xsl:text>
<xsl:value-of select = "b:City"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>).</xsl:text>
</p> -->
</xsl:template>
<xsl:template match = "b:Source[b:SourceType = 'BookSection']">
<p>
<!--AUTOR (Kurztitel, Jahr): Titel, in: Hrsg (Hrsg.), Buchtitel, Jahr, S. 277 - 299 -->
<i> <!--Autorenliste-->
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
</i>
<xsl:text> (</xsl:text>
<xsl:value-of select = "b:ShortTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>): </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text>, in: </xsl:text>
<i>
<xsl:apply-templates select = "b:Author/b:BookAuthor" mode="BookAuthorNamelistFull" />
</i>
<xsl:text> (Hrsg.), </xsl:text>
<xsl:value-of select = "b:BookTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>, S. </xsl:text>
<xsl:value-of select = "b:Pages"/>
</p>
</xsl:template>
<!--Extra Eintrag fuer HRSG. vom Sammelband-->
<xsl:template match = "b:Source[b:SourceType = 'BookSection']" mode="ExtraBookAuthorEntry">
<p>
<i>
<xsl:apply-templates select="b:Author/b:BookAuthor" mode="BookAuthorNamelistFull" />
</i>
<xsl:text> (Hrsg.) (</xsl:text>
<!--TODO fuer ShortTitel vom Sammelband!!-->
<xsl:value-of select = "b:ShortTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>): </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text>, </xsl:text>
<xsl:if test="b:Edition != ''">
<xsl:value-of select = "b:Edition"/>
<xsl:text>. Aufl., </xsl:text>
</xsl:if>
<xsl:value-of select = "b:City"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="b:Publisher"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
</p>
</xsl:template>
<xsl:template match="b:Source[b:SourceType = 'ArticleInAPeriodical']">
<p>
<!--AUTOR (Kurztitel, Jahr): Titel, in: Hrsg (Hrsg.), Buchtitel, Jahr, S. 277 - 299 -->
<i> <!--Autorenliste-->
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
</i>
<xsl:text> (</xsl:text>
<xsl:value-of select = "b:ShortTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>): </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text>, in: </xsl:text>
<xsl:value-of select = "b:PeriodicalTitle" />
<xsl:text>, </xsl:text>
<xsl:if test="b:Volume != ''">
<xsl:value-of select = "b:Volume"/>
<xsl:text></xsl:text>
</xsl:if>
<xsl:text>(</xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>), </xsl:text>
<xsl:if test="b:Issue != ''">
<xsl:text>Nr. </xsl:text>
<xsl:value-of select = "b:Issue"/>
</xsl:if>
<xsl:text>, S. </xsl:text>
<xsl:value-of select = "b:Pages"/>
</p>
</xsl:template>
<xsl:template match = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']">
<p>
<i> <!--Autorenliste-->
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
</i>
<xsl:text> (</xsl:text>
<xsl:value-of select = "b:ShortTitle"/>
<xsl:text>, </xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>): </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text>, <</xsl:text>
<xsl:value-of select = "b:URL"/>
<xsl:text>> </xsl:text>
<xsl:text>(</xsl:text>
<xsl:value-of select = "b:Day"/>
<xsl:text>.</xsl:text>
<xsl:value-of select = "b:Month"/>
<xsl:text>.</xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>) </xsl:text>
<xsl:text>[Zugriff: </xsl:text>
<xsl:value-of select = "b:DayAccessed"/>
<xsl:text>.</xsl:text>
<xsl:value-of select = "b:MonthAccessed"/>
<xsl:text>.</xsl:text>
<xsl:value-of select = "b:YearAccessed"/>
<xsl:text>]</xsl:text>
<!-- <xsl:if test="b:Edition != ''">
<xsl:value-of select = "b:Edition"/>
<xsl:text>. Aufl., </xsl:text>
</xsl:if> -->
</p>
</xsl:template>
<!--
<xsl:template match = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']">
<p style="font-family: Arial, Helvetica, sans-serif; font-size: 11pt;">
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistFull" />
<xsl:text>: </xsl:text>
<xsl:value-of select = "b:Title"/>
<xsl:text> (</xsl:text>
<xsl:value-of select = "b:Year"/>
<xsl:text>) </xsl:text>
<br />
<span style="font-size: 10pt; color: #0000FF;">
<xsl:text>[</xsl:text>
<xsl:value-of select = "b:URL"/>
<xsl:text>]</xsl:text>
</span>
<span style="font-size: 10pt;">
<xsl:text> (Zugriff am: </xsl:text>
<xsl:value-of select = "b:DayAccessed"/>
<xsl:text>. </xsl:text>
<xsl:value-of select = "b:MonthAccessed"/>
<xsl:text>.</xsl:text>
<xsl:value-of select = "b:YearAccessed"/>
<xsl:text>).</xsl:text>
</span>
</p>
</xsl:template> -->
<!--FINISH Label the paragraph as an Office Bibliography paragraph-->
<!--### Abschnitt 3: Ausgabe im Literaturverzecihnis -->
<xsl:template match="b:Bibliography">
<html xmlns="https://www.w3.org/TR/REC-html40">
<body>
<xsl:variable name="Literatur">
<xsl:apply-templates select ="b:Source[b:SourceType = 'BookSection'] | b:Source[b:SourceType = 'Book'] | b:Source[b:SourceType = 'ArticleInAPeriodical']" />
<xsl:apply-templates select ="b:Source[b:SourceType = 'BookSection']" mode="ExtraBookAuthorEntry" />
</xsl:variable>
<xsl:copy-of select="$Literatur"/>
<span style="font-size: 12pt; font-family: 'TimesNewRoman'; font-weight: bold;">
<xsl:text>Internetquellen</xsl:text>
</span>
<xsl:apply-templates select = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']">
<xsl:sort select="b:Tag" order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<!--<xsl:template match="b:Bibliography">
<html xmlns="http://www.w3.org/TR/REC-html40">
<body>
<xsl:apply-templates select ="b:Source[b:SourceType = 'Book']">
</xsl:apply-templates>
<xsl:apply-templates select = "b:Source[b:SourceType = 'Book'] | b:Source[b:SourceType = 'BookSection']">
<xsl:sort select="b:Tag" order="ascending"/>
</xsl:apply-templates>
<xsl:text>Onlinequellen</xsl:text>
<xsl:apply-templates select = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']">
<xsl:sort select="b:Tag" order="ascending"/>
</xsl:apply-templates>
<br/>
</body>
</html>
</xsl:template>-->
<!--### Abschnitt 4: Hier wird festgelegt, wie einzelne Zitate ausgegeben werden.###-->
<xsl:template match = "b:Citation/b:Source">
<html xmlns = "http://www.w3.org/TR/REC-html40">
<body>
<!--Zu erst kommt das Tag, Bsp: [VanV]
<span style="font-weight:bold">
<xsl:text>[</xsl:text>
<xsl:value-of select = "b:Tag"/>
<xsl:text>] </xsl:text>
</span>-->
<!-- Autoren-->
<!--Anmerkung: Wie die Liste genau aufgebaut ist, steht in Abschnitt 5-->
<i>
<xsl:apply-templates select="b:Author/b:Author" mode="AuthorNamelistShort" />
</i>
<xsl:apply-templates select="b:Author/b:Interviewee" mode="AuthorNamelistVeryShort" />
<xsl:text>, </xsl:text>
<!--Schlagwort-->
<xsl:value-of select="b:ShortTitle"/>
<xsl:text>, </xsl:text>
<!--Datum-->
<xsl:value-of select = "b:Year"/>
<!--und noch die Seiten, wenn sie angegeben wurden-->
<xsl:if test="../b:Pages != ''">
<xsl:text>, S. </xsl:text>
<xsl:value-of select = "../b:Pages"/>
</xsl:if>
</body>
</html>
</xsl:template>
<!--### Abschnitt 5: Hier wird festgelegt, wie die verschieden langen Autoren- bzw- Interviewpartnerlisten ausgegeben werden.###-->
<!-- Vollständige Interviewpartnerliste -->
<xsl:template match="b:Interviewee" mode="IntervieweeNamelistFull">
<xsl:for-each select="b:NameList/b:Person">
<xsl:apply-templates select="."/>
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="b:Corporate"/>
</xsl:template>
<!-- Vollständige Autorenliste -->
<xsl:template match="b:Author" mode="AuthorNamelistFull">
<!--<xsl:for-each select="b:NameList/b:Person">-->
<xsl:for-each select="b:NameList/b:Person">
<xsl:apply-templates select="."/>
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="b:Corporate"/>
</xsl:template>
<!-- Vollständige Hrsg. Liste -->
<xsl:template match="b:BookAuthor" mode="BookAuthorNamelistFull">
<!--<xsl:for-each select="b:NameList/b:Person">-->
<xsl:for-each select="b:NameList/b:Person">
<xsl:apply-templates select="."/>
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="b:Corporate"/>
</xsl:template>
<xsl:template match="b:Author" mode="AuthorNamelistShort">
<xsl:for-each select="b:NameList/b:Person">
<xsl:choose>
<xsl:when test="position() = 2">
<xsl:choose>
<xsl:when test="last() > 2">
<xsl:text> et al.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="." mode="FirstShort" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="position() > 2">
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="FirstShort" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:value-of select="b:Corporate"/>
</xsl:template>
<!--### Abschnitt 6: Hier wird festgelegt, wie der Name einer Einzelnen Person aufgebaut ist.###-->
<!-- Beispiel: "Vorname Vorname2 Nachname" -->
<xsl:template match="b:Person">
<xsl:if test="b:Last != ''">
<xsl:value-of select = "b:Last"/>
</xsl:if>
<xsl:text>, </xsl:text>
<xsl:if test="b:First != ''">
<xsl:value-of select = "b:First"/>
</xsl:if>
<xsl:if test="b:Middle != ''">
<xsl:text></xsl:text>
<xsl:value-of select = "b:Middle"/>
</xsl:if>
</xsl:template>
<xsl:template match="b:Person" mode="FirstShort">
<xsl:if test="b:Last != ''">
<xsl:value-of select = "b:Last"/>
</xsl:if>
<xsl:text>, </xsl:text>
<xsl:if test="b:First != ''">
<xsl:value-of select = "substring(b:First, 1,1)"/>
<xsl:text>.</xsl:text>
</xsl:if>
<xsl:if test="b:Middle != ''">
<xsl:text></xsl:text>
<xsl:value-of select = "substring(b:Middle, 1,1)"/>
<xsl:text>.</xsl:text>
</xsl:if>
</xsl:template>
<!--<xsl:value-of select="substring(b:Author/b:Author/b:NameList/b:Person/b:First, 1,1)" />-->
<xsl:template match="text()" />
</xsl:stylesheet>
解决方案
您可以尝试对变量的内容进行排序,但在 XSLT 1 中,这只能使用专有扩展功能,因此对于 MS Word 尝试
<xsl:variable name="p-elements" select="msxml:node-set($Literatur)/p" xmlns:msxml="urn:schemas-microsoft-com:xslt"/>
<xsl:for-each select="$p-elements">
<xsl:sort select="i"/>
<xsl:copy-of select="."/>
</xsl:for-each>
而不是xsl:copy-of select="$Literatur"/>
.
推荐阅读
- elasticsearch-opendistro - 如何在 Open Distro 上进行基本身份验证?
- java - 试图将 rgb 值转换为十六进制
- pandas - ValueError:当 HDF5 文件包含多个数据集时必须提供密钥,同时在 pandas 中读取 h5 文件我收到此错误
- php - 如何将会话 ID 与全部请求一起存储?
- php - Laravel 5.7 错误返回 response()->json(['content'=>'a
b]); 然后它变成 - java - 如何使用 Java 机器人类获取按键欧洲“è”字符
- if-statement - 使用 if 和 Else 在 R 中渲染文本时出现问题
- python - 如何使用 Python 从 USB 读取数据?(pyUSB)
- javascript - v模型值变化时触发哪个事件
- google-sheets - 条件格式 - 一个范围内的单元格具有来自另一个范围的匹配值