Page 1 of 1
Help a newbie with XML tranforming
Posted: Sun May 13, 2007 9:24 am
by tutukun
Hi,
I'm trying some xml to html examples, and I'm kinda stuck. For example i have the following xml
Code: Select all
<para>
Hi pls visit my website at <url>http://www.abc.com</url>.
</para>
Could anyone help me form it into something that look like:
using XSLT?
Sorry for my bad english.
Thank you

Posted: Sun May 13, 2007 7:59 pm
by george
You can start with a recursive copy template and then add in two rules (templates) to hanle your two cases:
Code: Select all
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="url">
<a href="{.}"><xsl:value-of select="."/></a>
</xsl:template>
</xsl:stylesheet>
Regards,
George
Posted: Sun May 13, 2007 8:22 pm
by tutukun
george wrote:You can start with a recursive copy template and then add in two rules (templates) to hanle your two cases:
Code: Select all
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="url">
<a href="{.}"><xsl:value-of select="."/></a>
</xsl:template>
</xsl:stylesheet>
Regards,
George
This is exactly what I need. Thank you very much
