Link to home
Start Free TrialLog in
Avatar of Boopathy S
Boopathy SFlag for India

asked on

I want to reassemble the element using XSLT

Hi, My Input file is:

<p><b><img src="https://admin.com"/>abc</b> efgh</p>

XSL I tried as:

   <xsl:template match="p[b[img]]">
      <xsl:value-of select="img"/>
      <xsl:apply-templates/>
   </xsl:template>

Expected Output be like:

<img src="https://admin.com"/>
<p><b>abc</b> efgh</p>

Please provide me the suggestion XSL code. Thanks in advance.
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

xsl:value-of only returns the string content of the element
xsl:copy-of would return the whole lot

also note that you have a context issue, img is NOT a child of p but a child of b

<xsl:template match="p[b[img]]">
      <xsl:copy-of select="b/img"/>
      <xsl:apply-templates/>
   </xsl:template>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Boopathy S

ASKER

Thanks