Help a newbie with XML tranforming

Here should go questions about transforming XML with XSLT and FOP.
tutukun
Posts: 2
Joined: Sun May 13, 2007 9:17 am

Help a newbie with XML tranforming

Post 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:
Hi pls visit my website at http://www.abc.com
using XSLT?

Sorry for my bad english.

Thank you :)
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
George Cristian Bina
tutukun
Posts: 2
Joined: Sun May 13, 2007 9:17 am

Post 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 :)
Post Reply