【问题标题】:XSL: Combine output of two apply-templates and sort themXSL:组合两个应用模板的输出并对它们进行排序
【发布时间】:2020-10-25 20:53:11
【问题描述】:

亲爱的,目前我正在 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>, &lt;</xsl:text>
         <xsl:value-of select = "b:URL"/>
         <xsl:text>&gt; </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 2 吗?在这种情况下,您可以使用&lt;xsl:perform-sort select="$Literatur/b:Source"/&gt;&lt;xsl:sort select="your sort expression here"/&gt;&lt;/xsl:perform-sort&gt; 而不是副本。实际上建议是在变量上使用xsl:perform-sort,我不确定它是否包含b:Source 元素或一些结果元素,因此您可能需要调整select 表达式。
  • 谢谢,但这没有用。你有别的想法吗?顺便说一句:我使用以下标题:&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;xsl:output method="html" encoding="utf-8"/&gt;
  • 首先告诉我们您是否使用 XSLT 2 或 3 处理器,如 Saxon 9 或 10、XmlPrime 或 Altova,否则您可以忘记我使用 perform-sort 的建议。在 MS Word 的上下文中,我不确定您使用的是仅支持 XSLT 1 的 Microsoft XSLT 处理器。此外,如果您向我们展示您想要排序的内容,这将有所帮助,不清楚您的模板是什么样的结果生产和你想要的排序。至于“不起作用”,请告诉我们您尝试了什么并解释它是如何失败的(确切的错误或您得到的确切结果)。
  • 亲爱的 Martin,我没有看到任何错误日志,因为它是 Word……我只能看到我的参考书目在那之后就没有工作了。 (因为它是 Word,所以我认为我不必跟踪错误。)我认为它是 XSL 版本 1(我认为是因为我的文件的标题)--> xmlns:xsl="w3.org/1999/XSL/Transform "
  • 我想根据 b:Tag 或 b:Author 对参考书目中的条目进行排序。此示例在我要输出条目的部分内工作:&lt;xsl:apply-templates select = "b:Source[b:SourceType = 'InternetSite'] | b:Source[b:SourceType = 'DocumentFromInternetSite']"&gt; &lt;xsl:sort select="b:Tag" order="descending"/&gt; &lt;/xsl:apply-templates&gt; 当我输出 3 个应用模板时,我可以在它们的输出中对它们进行排序,但是我可能有这样排序的条目:A、B、C A,A,B

标签: xslt xslt-1.0 word bibliography


【解决方案1】:

您可以尝试对变量的内容进行排序,但在 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"/&gt;

【讨论】:

  • 亲爱的马丁,非常感谢。这对我有用。我得到了正确和希望的输出:)
猜你喜欢
  • 2023-03-18
  • 2022-10-04
  • 2016-09-23
  • 2020-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-05
  • 2016-12-03
相关资源
最近更新 更多