2017-12-04 5 views
1

Ich habe das Bildelement, dessen Überspringen, während ich die XSL-Umwandlung konvertiere, Bitte machen Sie es möglich, in meinem bereitgestellten Code zu ändern. weil der dieser Code auch mit vielen Input-Dateien arbeitet,Bildelemente überspringen beim Konvertieren XSL

Meine XML-Input-:

<Body> 
<h1>Local</h1> 
<p>Early</p> 
<h2>Home</h2> 
<h3>Medicines</h3> 
<p>Home</p> 
<h3>General</h3> 
<p> 
<img alt="Man" height="187" width="300" class="right" src="https://tneb.com" /> 
</p> 
<ul> 
<li> 
<p>Itching</p> 
</li> 
<li> 
<p>pack</p> 
</li> 
</ul> 
</Body> 

XSLT 2.0 Ich habe verwendet und ich umgewandelt, indem die Saxon mit - PE 9.6.0.7,

<xsl:template match="Body"> 
     <xsl:for-each-group select="*[normalize-space()]" group-starting-with="h1"> 
     <topic outputclass=""> 
      <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5"/></xsl:attribute> 
      <title outputclass=""> 
       <xsl:apply-templates select="node()"/> 
      </title> 

      <xsl:for-each-group select="current-group() except ." group-starting-with="h2 | div[@data-swiq-type='callout-box']"> 
       <xsl:choose> 
        <xsl:when test="self::h2"> 
        <topic outputclass="TOPIC-Section"> 
         <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
         <title outputclass="Section"> 
          <xsl:apply-templates select="node()"/> 
         </title> 

         <xsl:for-each-group select="current-group() except ." group-starting-with="h3 | div[@data-swiq-type='callout-box']"> 
          <xsl:choose> 
           <xsl:when test="self::h3"> 
           <topic outputclass="TOPIC-Sub-Section"> 
            <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
            <title outputclass="Sub-Section"> 
             <xsl:apply-templates select="node()"/> 
            </title> 

            <xsl:for-each-group select="current-group() except ." group-starting-with="h4 | div[@data-swiq-type='callout-box']"> 
             <xsl:choose> 
              <xsl:when test="self::h4"> 
              <topic outputclass="TOPIC-Sub-Section"> 
               <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
               <title outputclass="Sub-Section"> 
                <xsl:apply-templates select="node()"/> 
               </title> 

               <xsl:for-each-group select="current-group() except ." group-starting-with="h5 | div[@data-swiq-type='callout-box']"> 
                <xsl:choose> 
                 <xsl:when test="self::h5"> 
                 <topic outputclass="TOPIC-Sub-Section"> 
                  <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
                  <title outputclass="Sub-Section"> 
                   <xsl:apply-templates select="node()"/> 
                  </title> 


                  <body><xsl:apply-templates select="current-group() except ."/></body> 
                 </topic> 
                 </xsl:when> 
                 <xsl:when test="self::div[@data-swiq-type='callout-box']"> 
                 <topic outputclass="TOPIC-Box"> 
                  <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
                  <title><xsl:value-of select="h5"/></title> 
                  <body><xsl:apply-templates/></body> 
                 </topic> 
                 </xsl:when> 
                 <xsl:otherwise> 
                 <body><xsl:apply-templates select="current-group()"/></body> 
                 </xsl:otherwise> 
                </xsl:choose> 
               </xsl:for-each-group> 

               </topic> 
              </xsl:when> 
              <xsl:when test="self::div[@data-swiq-type='callout-box']"> 
              <topic outputclass="TOPIC-Box"> 
               <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
               <title><xsl:value-of select="h4"/></title> 
               <body><xsl:apply-templates/></body> 
              </topic> 
              </xsl:when> 
              <xsl:otherwise> 
              <body><xsl:apply-templates select="current-group()"/></body> 
              </xsl:otherwise> 
             </xsl:choose> 

            </xsl:for-each-group> 

           </topic>      
           </xsl:when> 
           <xsl:when test="self::div[@data-swiq-type='callout-box']"> 
           <topic outputclass="TOPIC-Box"> 
            <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
            <title><xsl:value-of select="h3"/></title> 
            <body><xsl:apply-templates/></body> 
           </topic> 
           </xsl:when> 
           <xsl:otherwise> 
           <body><xsl:apply-templates select="current-group()"/></body> 
           </xsl:otherwise> 
          </xsl:choose> 

         </xsl:for-each-group> 
        </topic> 
        </xsl:when> 
        <xsl:when test="self::div[@data-swiq-type='callout-box']"> 
        <topic outputclass="TOPIC-Box"> 
         <xsl:attribute name="id">topic_<xsl:number count="h1 | h2 | h3 | h4 | h5 | div"/></xsl:attribute> 
         <title outputclass=""><xsl:value-of select="h2 | h3 | h4 | h5"/></title> 
         <body><xsl:apply-templates/></body> 
        </topic> 
        </xsl:when> 
        <xsl:otherwise> 
        <body><xsl:apply-templates select="current-group()"/></body> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:for-each-group> 
     </topic> 
     </xsl:for-each-group> 
    </xsl:template> 

    <xsl:template match="p"> 
     <xsl:choose> 
     <xsl:when test="not(text()[normalize-space(.)] | child::*)"/> 
     <xsl:otherwise> 
      <p outputclass="Body_text_no_indent"> 
       <xsl:apply-templates/> 
      </p>    
     </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

     <xsl:template match="img"> 
     <xsl:element name="image"> 
      <xsl:if test="@imageid"> 
       <xsl:attribute name="id"><xsl:value-of select="@imageid"/></xsl:attribute> 
      </xsl:if> 
      <xsl:if test="@title"> 
       <xsl:attribute name="xtrf"><xsl:apply-templates select="@title"/></xsl:attribute> 
      </xsl:if> 
      <xsl:if test="@src"> 
       <xsl:attribute name="href"> 
        <xsl:variable name="resolutionremove"> 
        <xsl:value-of select="tokenize(@src, '/')[position() = last() - 2 or position() = last()]" separator="_"/> 
        </xsl:variable> 
        <xsl:value-of select="replace($resolutionremove, '.([0-9]+)x([0-9]+)', '')"/> 
       </xsl:attribute> 
      </xsl:if> 
      <xsl:if test="@alt"> 
      <xsl:attribute name="alt"><xsl:apply-templates select="@alt"/></xsl:attribute> 
      </xsl:if> 
     <xsl:if test="@height"> 
      <xsl:attribute name="height"><xsl:value-of select="@height"/></xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@width"> 
      <xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@align"> 
      <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute> 
     </xsl:if> 
      <xsl:if test="@data-image"> 
       <xsl:attribute name="base">data-image(<xsl:value-of select="@data-image"/>)</xsl:attribute> 
      </xsl:if>    
     <xsl:attribute name="outputclass">Image_Ref</xsl:attribute> 
     </xsl:element> 
    </xsl:template> 

<xsl:template match="ul" priority="0"> 
     <ul outputclass=""> 
     <xsl:apply-templates/> 
     </ul> 
    </xsl:template> 

    <xsl:template match="ul/li" priority="0"> 
     <li outputclass="List_Bullet"> 
     <xsl:apply-templates/> 
     <xsl:apply-templates select="following-sibling::*[1][self::ul]" mode="wrap"/> 
     </li> 
    </xsl:template> 

Während ich konvertiere, wird das Bildelement übersprungen, wenn ich dieses img innerhalb des List-Tags benutze, kommt es. Kann mir bitte jemand den Vorschlag dafür machen. Bitte ändern Sie den Code der Body-Vorlage. Vielen Dank im Voraus

Antwort

3

ändern

<xsl:for-each-group select="*[normalize-space()]" group-starting-with="h1"> 

zu

<xsl:for-each-group select="*[node()]" group-starting-with="h1"> 
+0

Dank @Rupesh, seine Arbeit gut. – User501

Verwandte Themen