Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace div tag with p tag only if it does not have direct childs as p/ol/ul tags

I need to replace div tag with p tag only if div tag doesn’t contains direct child as p/ol/ul tag and if it contains p/ol/ul tag as direct child then just remove the div tag and keep the child tags as it is.

Example:

 <div>
      <ul>
         <li>HIPAA Privacy Module Certificate</li>
      </ul>
  </div>
 <div>
      <p>
         HIPAA Privacy Module Certificate
      </p>
  </div>
 <div>
      <strong>
         <li>HIPAA Privacy Module Certificate</li>
      </strong>
  </div>

Desired output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  <ul>
      <li>HIPAA Privacy Module Certificate</li>
  </ul>
  <p>
     HIPAA Privacy Module Certificate
  </p>
 <p>
      <strong>
         <li>HIPAA Privacy Module Certificate</li>
      </strong>
  </p>

What i’m trying but didn’t work:

    <xsl:template match="div[not(div)]">
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>
 <xsl:template match="ul[(parent::div)]">
            <ul>
                <xsl:apply-templates/>
            </ul>

    </xsl:template>


<xsl:template match="ol[(parent::div)]">
                <ol>
                    <xsl:apply-templates/>
                </ol>
    
        </xsl:template>
 <xsl:template match="p[(parent::div)]">
                <p>
                    <xsl:apply-templates/>
                </p>
    
        </xsl:template>

Thanks in advance.

>Solution :

To me it sounds like doing

<xsl:template match="div[p | ol | ul]">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="div[not(p | ol | ul)]">
  <p>
    <xsl:apply-templates/>
  </p>
</xsl:template>

together with the identity transformation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading