XSLT 1.0使用后代

时间:2016-04-26 19:05:52

标签: xslt-1.0

您好,并提前感谢您。

我尝试使用xslt 1.0转换长而复杂的xml文档。源文档的一部分如下:

<c id="hou01965c00171" level="series">
        <did>
           <unittitle>Index </unittitle>
        </did>
        <c id="hou01965c00172" level="subseries">
           <did>
              <unittitle>A</unittitle>
           </did>
           <c id="hou01965c00179">
              <did>
                 <unitid>(MS Sparks 132) </unitid>
                 <unittitle>
                    <persname>Abbot, Benjamin. </persname>
                    <geogname>Exeter, N. H. </geogname>-Teaching certificate for <persname>Jared
                       Sparks.</persname> Dec. 18, <unitdate calendar="gregorian"
                       datechar="single" endYear="1810" era="ce" startYear="1810"
                       >1810.</unitdate>
                 </unittitle>
              </did>
              <note>
                 <p>Misc. Paps. I, (14)</p>
                 <p>ORIGINAL</p>
              </note>
           </c>
           <c id="hou01965c00173">
              <did>
                 <unitid>(MS Sparks 70) </unitid>
                 <unittitle>A.B. [Haldimand's secret agent] To E. Apr. <unitdate
                       calendar="gregorian" datechar="single" endYear="1782" era="ce"
                       startYear="1782">1782.</unitdate>
                 </unittitle>
              </did>
              <note>
                 <p>Vermont Paps., <date calendar="gregorian" endYear="1782" era="ce"
                       startYear="1780">1780-1782, </date>89-90.</p>
              </note>
           </c>
           <c id="hou01965c00174">
              <did>
                 <unitid>(MS Sparks 85) </unitid>
                 <unittitle>
                    <persname>D'Abancourt </persname>to <persname>Lafayette.</persname>
                 </unittitle>
              </did>
              <note>
                 <p>
                    <list>
                       <item>June 26, <date calendar="gregorian" endYear="1792" era="ce"
                             startYear="1792">1792: </date>178-80. </item>
                       <item>July 26, <date calendar="gregorian" endYear="1792" era="ce"
                             startYear="1792">1792: </date>222. </item>
                       <item>July 30, <date calendar="gregorian" endYear="1792" era="ce"
                             startYear="1792">1792: </date>222-1.</item>
                    </list>
                 </p>
                 <p>Lafayette Letters, <date calendar="gregorian" endYear="1792" era="ce"
                       startYear="1777">1777-1792 </date>(2).</p>
              </note>
           </c>
           <c id="hou01965c00175">
              <did>
                 <unitid>(MS Sparks 153) </unitid>
                 <unittitle>
                    <persname>Abbey, W. M. </persname>To <persname>Jared Sparks.</persname> Feb.
                    19, <unitdate calendar="gregorian" datechar="single" endYear="1857" era="ce"
                       startYear="1857">1857, </unitdate>
                    <geogname>Philadelphia.</geogname>
                 </unittitle>
              </did>
              <note>
                 <p>Letters to Sparks.</p>
                 <p>ORIGINAL</p>
              </note>
           </c>
           <c id="hou01965c00176">
              <did>
                 <unitid>(MS Sparks 153) </unitid>
                 <unittitle>
                    <persname>Abbot, Anne W. </persname>To <persname>Mrs. Sparks.</persname> ---
                       <unitdate calendar="gregorian" datechar="single" endYear="1853" era="ce"
                       startYear="1853">1853.</unitdate>
                 </unittitle>
              </did>
              <note>
                 <p>Letters to Sparks.</p>
                 <p>ORIGINAL</p>
              </note>
           </c>
        </c>
      </c>

我想按原样返回c / c / c节点,包括元素标签,但我希望它们根据<unitid>的值进行排序。 <unitid>的值是字母数字,例如(MS Sparks 70),(MS Sparks 85)。

这是我的xslt

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="/ead/archdesc[1]/dsc[1]/c[4]/c/c/did">
    <xsl:copy><xsl:apply-templates><xsl:sort select="unitid/text()"></xsl:sort></xsl:apply-templates></xsl:copy>
</xsl:template>

忽略模板匹配模式中的谓词,指的是更长的文档。

我的结果文档中没有任何不同之处。它基本上复制了源文档。

这就是我想要的输出:

<c id="hou01965c00173">
          <did>
             <unitid>(MS Sparks 70) </unitid>
             <unittitle>A.B. [Haldimand's secret agent] To E. Apr. <unitdate
                   calendar="gregorian" datechar="single" endYear="1782" era="ce"
                   startYear="1782">1782.</unitdate>
             </unittitle>
          </did>
          <note>
             <p>Vermont Paps., <date calendar="gregorian" endYear="1782" era="ce"
                   startYear="1780">1780-1782, </date>89-90.</p>
          </note>
       </c>
       <c id="hou01965c00174">
          <did>
             <unitid>(MS Sparks 85) </unitid>
             <unittitle>
                <persname>D'Abancourt </persname>to <persname>Lafayette.</persname>
             </unittitle>
          </did>
          <note>
             <p>
                <list>
                   <item>June 26, <date calendar="gregorian" endYear="1792" era="ce"
                         startYear="1792">1792: </date>178-80. </item>
                   <item>July 26, <date calendar="gregorian" endYear="1792" era="ce"
                         startYear="1792">1792: </date>222. </item>
                   <item>July 30, <date calendar="gregorian" endYear="1792" era="ce"
                         startYear="1792">1792: </date>222-1.</item>
                </list>
             </p>
             <p>Lafayette Letters, <date calendar="gregorian" endYear="1792" era="ce"
                   startYear="1777">1777-1792 </date>(2).</p>
          </note>
       </c>
    <c id="hou01965c00179">
              <did>
                 <unitid>(MS Sparks 132) </unitid>
                 <unittitle>
                    <persname>Abbot, Benjamin. </persname>
                    <geogname>Exeter, N. H. </geogname>-Teaching certificate for <persname>Jared
                       Sparks.</persname> Dec. 18, <unitdate calendar="gregorian"
                       datechar="single" endYear="1810" era="ce" startYear="1810"
                       >1810.</unitdate>
                 </unittitle>
              </did>
              <note>
                 <p>Misc. Paps. I, (14)</p>
                 <p>ORIGINAL</p>
              </note>
           </c>
       <c id="hou01965c00175">
          <did>
             <unitid>(MS Sparks 153) </unitid>
             <unittitle>
                <persname>Abbey, W. M. </persname>To <persname>Jared Sparks.</persname> Feb.
                19, <unitdate calendar="gregorian" datechar="single" endYear="1857" era="ce"
                   startYear="1857">1857, </unitdate>
                <geogname>Philadelphia.</geogname>
             </unittitle>
          </did>
          <note>
             <p>Letters to Sparks.</p>
             <p>ORIGINAL</p>
          </note>
       </c>
       <c id="hou01965c00176">
          <did>
             <unitid>(MS Sparks 153) </unitid>
             <unittitle>
                <persname>Abbot, Anne W. </persname>To <persname>Mrs. Sparks.</persname> ---
                   <unitdate calendar="gregorian" datechar="single" endYear="1853" era="ce"
                   startYear="1853">1853.</unitdate>
             </unittitle>
          </did>
          <note>
             <p>Letters to Sparks.</p>
             <p>ORIGINAL</p>
          </note>
       </c>
     </c>
    </c>

0 个答案:

没有答案