Skip to content Skip to sidebar Skip to footer

Xslt Insert Html Content

I'm trying to insert some HTML at a given point. The XML file has a content node, which inside that has actual HTML. For exmaple here is the content section of the XML: -----------

Solution 1:

Given this source:

<html><head/><body><content><h2>Header</h2><p><ahref="...">some link</a></p><p><ahref="...">some link1</a></p><p><ahref="...">some link2</a></p></content></body></html>

This stylesheet will do what you want to do:

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:templatematch="@*|node()"><xsl:copy><xsl:apply-templatesselect="@*|node()"/></xsl:copy></xsl:template><xsl:templatematch="/html/body/content/h2"><xsl:copy><xsl:apply-templates/></xsl:copy><p><ahref="...">your new link</a></p></xsl:template></xsl:stylesheet>

Solution 2:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"><xsl:templatematch="/content"><xsl:copy-ofselect="h2"/><ahref="">foo</a><xsl:copy-ofselect="p"/></xsl:template></xsl:stylesheet>

Post a Comment for "Xslt Insert Html Content"