xsl-list
[Top] [All Lists]

[xsl] WorldML Filteration

2013-03-18 01:21:35
Hi, 
I have got a good clue about formatting elements for worldML. In the similar
effort we need to filter these elements. Comparison of "current output" and
"desired output" is sufficient to understand the requirement.

Input
<w:r><w:rPr><w:i/><w:i-cs/></w:rPr><w:t>Azienda</w:t></w:r>
<w:r><w:rPr><w:i/><w:i-cs/></w:rPr><w:t> </w:t></w:r>
<w:r><w:rPr><w:i/><w:b/><w:i-cs/></w:rPr><w:t>Ospedaliera</w:t></w:r>
<w:r><w:rPr><w:i/><w:b/><w:i-cs/></w:rPr><w:t>, </w:t></w:r>
<w:r><w:rPr><w:i/><w:i-cs/></w:rPr><w:t>Ospedali</w:t></w:r>
<w:r><w:rPr><w:i/><w:i-cs/></w:rPr><w:t> </w:t></w:r>
<w:proofErr w:type="spellStart"/>
<w:r><w:rPr><w:i/><w:i-cs/></w:rPr><w:t>Riuniti</w:t></w:r>

XSLT
<!--Text run container-->
 <xsl:template match="w:r">
  <xsl:choose>
   <xsl:when
test="w:rPr/w:vertAlign|w:rPr/w:u|w:rPr/w:b|w:rPr/w:i|w:rPr/w:smallCaps|w:rP
r/w:highlight">
    <xsl:apply-templates select="w:rPr" mode="styling"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:apply-templates/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

<!--Text run properties container-->
 <xsl:template match="w:rPr" mode="styling">
   <xsl:for-each select="child::w:*[1]">
     <xsl:variable name="name">
       <xsl:choose>
        <xsl:when test="local-name() eq 'b'">
         <xsl:value-of select="local-name()"/>
        </xsl:when>
        <xsl:when test="local-name() eq 'i'">
         <xsl:value-of select="local-name()"/>
        </xsl:when>
      </xsl:choose>
     </xsl:variable>
     <xsl:if test="$name!=''">
      <xsl:element name="{$name}">
       <xsl:call-template name="nestedTemplate"/>
      </xsl:element>
     </xsl:if>
     <xsl:if test="$name=''">
       <xsl:call-template name="nestedTemplate"/>
     </xsl:if>
   </xsl:for-each>  
 </xsl:template>

 <xsl:template name="nestedTemplate">
   <xsl:param name="inital" select="2"/>
   <xsl:choose>
     <xsl:when test="following-sibling::w:*[$inital - 1]">
      <xsl:variable name="name">
       <xsl:choose>
        <xsl:when test="following-sibling::w:*[$inital - 1]/local-name() eq
'b'">
         <xsl:value-of select="'b'"/>
        </xsl:when>
        <xsl:when test="following-sibling::w:*[$inital - 1]/local-name() eq
'i'">
         <xsl:value-of select="'i'"/>
        </xsl:when>
       </xsl:choose>
      </xsl:variable>  
      <xsl:if test="$name!=''">  
       <xsl:element name="{$name}">
        <xsl:if test="following-sibling::w:*[$inital - 1]">
          <xsl:call-template name="nestedTemplate">
            <xsl:with-param name="inital" select="$inital + 1"/>
           </xsl:call-template>
         </xsl:if>                
       </xsl:element>
      </xsl:if>
      <xsl:if test="$name=''">  
       <xsl:if test="following-sibling::w:*[$inital - 1]">
         <xsl:call-template name="nestedTemplate">
           <xsl:with-param name="inital" select="$inital + 1"/>
          </xsl:call-template>
        </xsl:if>                
      </xsl:if>
     </xsl:when>
     <xsl:otherwise>
       <xsl:apply-templates
select="parent::w:rPr/following-sibling::w:*[1][local-name()='t']"/>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>

Current output
<i>Azienda</i><i> </i><i><b>Ospedaliera</b></i><i><b>,
</b></i><i>Ospedali</i><i> </i><i>Riuniti</i>

Desired output
<i>Azienda <b>Ospedaliera, </b>Ospedali Riuniti</i>




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>