是否可能没有根元素组列表和输出中的输入根据输入xml到达特定位置

时间:2017-07-17 06:24:10

标签: xml xslt

没有根元素组列表和输出中的输入以根据输入xml

获取特定位置

我的输入XML:

<?xml version="1.0" encoding="UTF-8"?>
<topic outputclass="F_M" id="1234">
   <title outputclass="F_M_T">Officers</title>
   <body class="- topic/body ">
      <p outputclass="FM_B_S">Stregth• <br/>Caution• <br/>Artist • Dress</p>
      <p outputclass="FM_B_E">Edition</p>
      <p outputclass="FM_V">1</p>
      <image href="base/images/lan.png" outputclass="I_R"/>
      <p outputclass="FM_LH">Starter titles</p>
      <p outputclass="FM_LT">Commerce</p>
      <p outputclass="FM_L_B">Cartism</p>
      <p outputclass="FM_LT">Cat</p>
      <p outputclass="FM_L_B">Comunication</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_LT">TAMKEUPTCY BAN</p>
      <p outputclass="FM_L_B">Tankgruptgy Vesk</p>
      <p outputclass="FM_L_B">Resource Tankruptcy Book</p>
      <p outputclass="FM_O_I">Order now at www.ram.dev/ruds</p>
      <p outputclass="FM_O_I">Or call (900) 371-5645 Tue.–Wed., 5 a.m.–8 p.m.</p>
      <p outputclass="FM_P_A">Ram Institute</p>
      <p outputclass="FM_P_A">2255 Avenue of the Casinos</p>
      <p outputclass="FM_P_A">Melon Park, MP 20145</p>
      <p outputclass="FM_PC">States that the may undertake a review of the definition MLP5-Y.</p>
      <p outputclass="FM_B_T">States that the may undertake a review</p>
      <p outputclass="FM_B_S">Resource Tankruptcy Book<br/>• Resource Tankruptcy Book • States • Tankgruptgy<br/>• Definition • Melon Card</p>
      <p outputclass="FM_B_E">Book Edition</p>
      <p outputclass="FM_V">1</p>
      <p outputclass="FM_A">Ramesh G. Kumar, Sr.</p>
      <p outputclass="FM_I">Pre release number No. 50<br/>September 2016<br/>#256799</p>
      <p outputclass="FM_N_B">Ram Institute<br/>Melon Park City<br/>#25697</p>
      <p>
         <b>
            <br/>
         </b>
      </p>
      <p outputclass="FM_D">1Y The Act also states that the may undertake a review of the definition of the term.</p>
      <p outputclass="FM_Q">QUESTIONS ABOUT THIS BOOK?</p>
      <p outputclass="FM_Q">States that the may undertake a review of the definition of the term (900) 450-4RAM.</p>
      <p outputclass="FM_QT">States that the may undertake a review of the definition of the term (766) 199-6302 or email: brendoprecautions@ram.dev.</p>
      <p outputclass="FM_QT">States that the may undertake a review of the definition of the term at: redial@ram.dev.</p>
      <p outputclass="FM_QT">States that the may undertake a review of the definition of the term visit <xref format="html" href="YYYhttp://www.ram.dev" outputclass="regular">www.ram.dev</xref>.</p>
      <p outputclass="FM_LE">Common Prediction: Melln Gavagh</p>
      <p outputclass="FM_C">Ramright © 2014, 2015 by ram Institute. </p>
      <p outputclass="FM_C">Undertake a review of the definition. </p>
      <p outputclass="FM_C">States that the may undertake a review of the definition of the term ram Institute.</p>
      <p outputclass="FM_I_L">States that the may undertake a review of the definition of the term Number: 1921042468</p>
      <p outputclass="FM_I_L">ISBN: 969-2-3133-2664-8</p>
   </body>
</topic>

使用过的XSLT代码:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="topic[@outputclass='F_M']">
  <xsl:variable name="createdid" select="@id"/>
      <book create-date="June 2017" bid="{$createdid}">
        <xsl:apply-templates/>
      </book>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_B_S']">
    <subtitle>
      <xsl:apply-templates/>
    </subtitle>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_B_E']"/>

  <xsl:template match="p[@outputclass='FM_V']"/>

  <xsl:template match="p[@outputclass='LH']">
    <para>
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:key name="kFollowing2" match="p[@outputclass='FM_L_B'][preceding-sibling::*[1][self::p[@outputclass='FM_L_B']]]" use="generate-id(preceding-sibling::p[@outputclass='FM_L_B'][not(preceding-sibling::*[1][self::p[@outputclass='FM_L_B']])][1])"/>

  <xsl:template match="p[@outputclass='FM_L_B'][not(preceding-sibling::*[1][self::p[@outputclass='FM_L_B']])]">
    <publist>
      <xsl:call-template name="FM_L_B1"/>
      <xsl:apply-templates mode="copy" select="key('kFollowing2', generate-id())"/>
    </publist>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_L_B'][preceding-sibling::*[1][self::p[@outputclass='FM_L_B']]]"/>

  <xsl:template match="p[@outputclass='FM_L_B']" mode="copy" name="FM_L_B1">
    <publication><pubtitle><xsl:apply-templates/></pubtitle></publication>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_LT']">
    <para align="left"><content-style font-style="bold">
      <xsl:apply-templates/>
    </content-style></para>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_O_I']">
    <para align="center">
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_P_A']">
    <para align="center">
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_PC']">
    <para align="center">
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:template match="p[@outputclass='FM_D']">
    <legalnotice>
      <para><content-style font-style="italic">
      <xsl:apply-templates/>
      </content-style></para>
    </legalnotice>
  </xsl:template>

  <xsl:template match="image[@outputclass='I_R']">
    <figure>
      <xsl:attribute name="id" select="concat('fig_', format-number(count(preceding::image[@outputclass='Image_Ref'])+1,'000'))"/>
      <xsl:element name="graphic">
        <xsl:attribute name="href">
          <xsl:value-of select="substring-after(@href, 'base/images/')"/>
        </xsl:attribute>
        <xsl:attribute name="width">
            <xsl:value-of select="'100%'"/>
          </xsl:attribute>
      </xsl:element>
    </figure>
  </xsl:template>

  <xsl:template match="xref[@outputclass='regular']">
    <xsl:element name="uri">
      <xsl:attribute name="href">
        <xsl:value-of select="@href"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="body">
    <frontmatter>
      <seriesinfo>
        <pubhistory>

          <xsl:call-template name="FM_LT">
            <xsl:with-param name="FM_LT" select="p[@outputclass='FM_LT']"/>
          </xsl:call-template>
          <xsl:call-template name="FM_L_B">
            <xsl:with-param name="FM_L_B" select="p[@outputclass='FM_L_B']"/>
          </xsl:call-template>

          <xsl:call-template name="FM_O_I">
            <xsl:with-param name="FM_O_I" select="p[@outputclass='FM_O_I']"/>
          </xsl:call-template>
        </pubhistory>
        <xsl:call-template name="FM_PC">
          <xsl:with-param name="FM_PC" select="p[@outputclass='FM_PC']"/>
        </xsl:call-template>
      </seriesinfo>
      <xsl:call-template name="FM_D">
        <xsl:with-param name="FM_D" select="p[@outputclass='FM_D']"/>
      </xsl:call-template>
    </frontmatter>
  </xsl:template>

  <xsl:template name="FM_L_B">
    <xsl:param name="FM_L_B"/>
           <xsl:apply-templates select="$FM_L_B"/>
   </xsl:template>

  <xsl:template name="FM_LT">
    <xsl:param name="FM_LT"/>
    <para align="left">
      <content-style font-style="bold">
        <xsl:apply-templates select="$FM_LT"/>
      </content-style>
    </para>
  </xsl:template>
  <xsl:template name="FM_O_I">
    <xsl:param name="FM_O_I"/>
    <para align="center">
      <xsl:apply-templates select="$FM_O_I"/>
    </para>
  </xsl:template>
  <xsl:template name="FM_PC">
    <xsl:param name="FM_PC"/>
    <para align="center">
      <xsl:apply-templates select="$FM_PC"/>
    </para>
  </xsl:template>
  <xsl:template name="FM_D">
    <xsl:param name="FM_D"/>
    <legalnotice>
      <para>
        <content-style font-style="italic">
          <xsl:apply-templates select="$FM_D"/>
        </content-style>
      </para>
    </legalnotice>
  </xsl:template>
</xsl:transform>

输出我在一个地方得到所有'FM_LT'元素,'FM_L_B'元素是一个地方,如下所示:

但需要根据输入特定地点输出

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<book create-date="June 2017" bid="1234">

   <title outputclass="F_M_T">Officers</title>

   <frontmatter>
      <seriesinfo>
         <pubhistory>
            <para align="left">
               <content-style font-style="bold">
                  <para align="left">
                     <content-style font-style="bold">Commerce</content-style>
                  </para>
                  <para align="left">
                     <content-style font-style="bold">Cat</content-style>
                  </para>
                  <para align="left">
                     <content-style font-style="bold">TAMKEUPTCY BAN</content-style>
                  </para>
               </content-style>
            </para>
            <publist>
               <publication>
                  <pubtitle>Cartism</pubtitle>
               </publication>
            </publist>
            <publist>
               <publication>
                  <pubtitle>Comunication</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
            </publist>
            <publist>
               <publication>
                  <pubtitle>Tankgruptgy Vesk</pubtitle>
               </publication>
               <publication>
                  <pubtitle>Resource Tankruptcy Book</pubtitle>
               </publication>
            </publist>
            <para align="center">
               <para align="center">Order now at www.ram.dev/ruds</para>
               <para align="center">Or call (900) 371-5645 Tue.–Wed., 5 a.m.–8 p.m.</para>
            </para>
         </pubhistory>
         <para align="center">
            <para align="center">States that the may undertake a review of the definition MLP5-Y.</para>
         </para>
      </seriesinfo>
      <legalnotice>
         <para>
            <content-style font-style="italic">
               <legalnotice>
                  <para>
                     <content-style font-style="italic">1Y The Act also states that the may undertake a review of the definition of the term.</content-style>
                  </para>
               </legalnotice>
            </content-style>
         </para>
      </legalnotice>
   </frontmatter>

</book>

根据输入特定位置需要输出属性值作为第一个'FM_LT'值然后'FM_L_B'值再次'FM_LT'然后'FM_L_B'喜欢在输入中重复多少也只在输出中我需要输出如下所示:

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<book create-date="June 2017" bid="1234">

   <title>Officers</title>


   <subtitle>Stregth• <br/>Caution• <br/>Artist • Dress <content-style />Volume 1   </subtitle>

   <frontmatter>

   <figure id="fig_001">
      <graphic href="lan.png" width="100%"></graphic>
   </figure>
   <seriesinfo>
<pubhistory>
   <title>Starter titles</title>

   <para align="left">
      <content-style font-style="bold">Commerce</content-style>
   </para>

   <publist>
      <publication>
         <pubtitle>Cartism</pubtitle>
      </publication>
   </publist>

   <para align="left">
      <content-style font-style="bold">Cat</content-style>
   </para>

   <publist>
      <publication>
         <pubtitle>Comunication</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
   </publist>








   <para align="left">
      <content-style font-style="bold">TAMKEUPTCY BAN</content-style>
   </para>

   <publist>
      <publication>
         <pubtitle>Tankgruptgy Vesk</pubtitle>
      </publication>
      <publication>
         <pubtitle>Resource Tankruptcy Book</pubtitle>
      </publication>
   </publist>
   </pubhistory>

   <para align="center">Order now at www.ram.dev/ruds</para>

   <para align="center">Or call (900) 371-5645 Tue.–Wed., 5 a.m.–8 p.m.</para>

   <para align="center"><address><orgname>Ram Institute</orgname><street>2255 Avenue of the Casinos</street><city>Melon Park</city>, <state>MP</state><zipcode>20145</zipcode></address></para>

   <para align="center">States that the may undertake a review of the definition MLP5-Y.</para>
   </seriesinfo>
<bookinfo>
<title>States that the may undertake a review</title>
<otherinfo>
<para align="center">Resource Tankruptcy Book</para>
<para align="center">&#x2022; Resource Tankruptcy Book • States • Tankgruptgy<br>• Definition • Melon Card</para>
</otherinfo>
<authors>
<author><name><firstname>Ramesh </firstname><middlename>G. </middlename><surname>Kumar</surname>, <honorific>Sr.</honorific></name></author>
<printinfo differentiation="former">
<para align="center">Pre release number No. 50<br>September 2016<br>#256799
   </para>
</printinfo>
<publisherinfo>
<para align="center">Ram Institute<br>Melon Park City<br>#25697</para>
</publisherinfo>
   <legalnotice>
      <para>
         <content-style font-style="italic">1Y The Act also states that the may undertake a review of the definition of the term.</content-style>
      </para>
   </legalnotice>
<contactinfo>
<title>QUESTIONS ABOUT THIS BOOK?</title>
<para>States that the may undertake a review of the definition of the term <address><phone>(900) 450-4RAM</phone></address>.</para>

   <para>States that the may undertake a review of the definition of <address>the term <phone>(766) 199-6302</phone>
      or email: <email>brendoprecautions@ram.dev</email>.
   </para>

   <para>States that the may undertake a review of the definition of the term <address>at: <email>redial@ram.dev</email></address>.</para>

   <para>States that the may undertake a review of the definition of the term visit 
      <address><uri href="YYYhttp://www.ram.dev">www.ram.dev</uri></address>.
   </para>

   <copyright>
<para align="left">Common Prediction: Melln Gavagh</para>
<para align="left">Ramright © 2014, 2015 by ram Institute.  Undertake a review of the definition.  States that the may undertake a review of the definition of the term ram Institute.</para>
</copyright>
<catalogrecord><catalog><address />
<para align="center">States that the may undertake a review of the definition of the term Number: 1921042468</para>
</catalog></catalogrecord>
<isbn>ISBN: 969-2-3133-2664-8</isbn>
</bookinfo>
</frontmatter>
<body />
</book>

请帮助我

先谢谢

1 个答案:

答案 0 :(得分:0)

我认为您只需要使用params添加新的调用模板。

<xsl:template match="body">
    <frontmatter>
      <seriesinfo>
        <pubhistory>
          <xsl:call-template name="FM_LT">
            <xsl:with-param name="FM_LT" select="p[@outputclass='FM_LT'][1]/text()"/>
          </xsl:call-template>
          <xsl:call-template name="FM_L_B">
            <xsl:with-param name="FM_L_B" select="p[@outputclass='FM_L_B'][1]"/>
          </xsl:call-template>
          <xsl:call-template name="FM_LT">
            <xsl:with-param name="FM_LT" select="p[@outputclass='FM_LT'][2]/text()"/>
          </xsl:call-template>
          <xsl:call-template name="FM_L_B">
            <xsl:with-param name="FM_L_B" select="p[@outputclass='FM_L_B'][position()&gt; 1]"/>
          </xsl:call-template> 
          <xsl:call-template name="FM_LT">
            <xsl:with-param name="FM_LT" select="p[@outputclass='FM_LT'][3]/text()"/>
          </xsl:call-template>          
          <xsl:call-template name="FM_O_I">
            <xsl:with-param name="FM_O_I" select="p[@outputclass='FM_O_I']"/>
          </xsl:call-template>
        </pubhistory>
        <xsl:call-template name="FM_PC">
          <xsl:with-param name="FM_PC" select="p[@outputclass='FM_PC']"/>
        </xsl:call-template>
      </seriesinfo>
      <xsl:call-template name="FM_D">
        <xsl:with-param name="FM_D" select="p[@outputclass='FM_D']"/>
      </xsl:call-template>
    </frontmatter>
  </xsl:template>