You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Kostas Karadamoglou <ka...@yahoo.gr> on 2005/04/08 10:01:55 UTC
Problem: Cannot apply template of element with mixed data
Hi all,
My problem is the following:
In an xml-schema I have defined an element (content) that contains mixed
data. Specifically contains strings coupled with html tags and the
"code" element. Below I have an example of an instance:
<content>
<p>Before the code</p>
<code lang="xml">
<![CDATA[
System.out.println("Hello");
]]>
</code>
<p>After the code</p>
</content>
I have tried to create a template for the "content" but I cannot do it
properly. The xslt applies correctly the template of code but not the
remaining data (html script). It does not print the html tags.
The generated html returns the following html segment (notice that it
also returns the "content" tags):
<content>
Before the code
<i>System.out.println("Hello");</i>
After the code
</content>
Below I include the xslt template of the content element:
<xsl:template match="content">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Do you know how I will force xslt to print the html tags?
Thank you in advance, Kostas
Re: Problem: Cannot apply template of element with mixed data
Posted by Mukul Gandhi <ga...@gmail.com>.
node() | @* is being used as match pattern of the template.. node()
represents any node other than root and attribute nodes. @* represents
attribute nodes..
| operator is union operator ..
Regards,
Mukul
On Apr 8, 2005 5:05 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
> Mukul, thank you it works now!!!
>
> but I cannot understand the meaning of "node() | @*"
>
> Can you explain me?
>
> Thank you very much , Kostas.
>
> Mukul Gandhi wrote:
> > Probably you need a identity transform, and other templates for some
> > specific nodes.. If this is not ok! Please explain the problem bit
> > more clearly!
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >
> > <xsl:output method="html" />
> >
> > <xsl:template match="node() | @*">
> > <xsl:copy>
> > <xsl:apply-templates select="node() | @*" />
> > </xsl:copy>
> > </xsl:template>
> >
> > <xsl:template match="code">
> > <i><xsl:apply-templates /></i>
> > </xsl:template>
> >
> > <xsl:template match="content">
> > <xsl:apply-templates />
> > </xsl:template>
> >
> > </xsl:stylesheet>
> >
> > Regards,
> > Mukul
> >
> >
> > On Apr 8, 2005 2:45 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
> >
> >>Hi Mukul,
> >>
> >>I don't think that the xsl:copy-of is the best solution as you can see
> >>from the example xml code that I provided you in my first message the
> >>"content" element contains html tags and custom xml tags. I would like
> >>to deep copy html tags and apply templates to custom xml tags. If I use
> >>xsl:copy-of then the custom tags will not be applied.
> >>
> >
> >
>
>
Re: Problem: Cannot apply template of element with mixed data
Posted by Kostas Karadamoglou <ka...@yahoo.gr>.
Mukul, thank you it works now!!!
but I cannot understand the meaning of "node() | @*"
Can you explain me?
Thank you very much , Kostas.
Mukul Gandhi wrote:
> Probably you need a identity transform, and other templates for some
> specific nodes.. If this is not ok! Please explain the problem bit
> more clearly!
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="html" />
>
> <xsl:template match="node() | @*">
> <xsl:copy>
> <xsl:apply-templates select="node() | @*" />
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="code">
> <i><xsl:apply-templates /></i>
> </xsl:template>
>
> <xsl:template match="content">
> <xsl:apply-templates />
> </xsl:template>
>
> </xsl:stylesheet>
>
> Regards,
> Mukul
>
>
> On Apr 8, 2005 2:45 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
>
>>Hi Mukul,
>>
>>I don't think that the xsl:copy-of is the best solution as you can see
>>from the example xml code that I provided you in my first message the
>>"content" element contains html tags and custom xml tags. I would like
>>to deep copy html tags and apply templates to custom xml tags. If I use
>>xsl:copy-of then the custom tags will not be applied.
>>
>
>
Re: Problem: Cannot apply template of element with mixed data
Posted by Mukul Gandhi <ga...@gmail.com>.
Probably you need a identity transform, and other templates for some
specific nodes.. If this is not ok! Please explain the problem bit
more clearly!
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="code">
<i><xsl:apply-templates /></i>
</xsl:template>
<xsl:template match="content">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On Apr 8, 2005 2:45 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
> Hi Mukul,
>
> I don't think that the xsl:copy-of is the best solution as you can see
> from the example xml code that I provided you in my first message the
> "content" element contains html tags and custom xml tags. I would like
> to deep copy html tags and apply templates to custom xml tags. If I use
> xsl:copy-of then the custom tags will not be applied.
>
Re: Problem: Cannot apply template of element with mixed data
Posted by Kostas Karadamoglou <ka...@yahoo.gr>.
Hi Mukul,
I don't think that the xsl:copy-of is the best solution as you can see
from the example xml code that I provided you in my first message the
"content" element contains html tags and custom xml tags. I would like
to deep copy html tags and apply templates to custom xml tags. If I use
xsl:copy-of then the custom tags will not be applied.
Mukul Gandhi wrote:
> Hi Kostas,
> I think you need xsl:copy-of instead xsl:copy.. xsl:copy does
> shallow copy, whereas xsl:copy-of does deep copy..
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="xml" indent="yes" />
>
> <xsl:template match="/">
> <xsl:apply-templates select="content" />
> </xsl:template>
>
> <xsl:template match="content">
> <xsl:copy-of select="." />
> </xsl:template>
>
> </xsl:stylesheet>
>
> Regards,
> Mukul
>
>
> On Apr 8, 2005 1:31 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
>
>>Hi all,
>>
>>My problem is the following:
>>
>>In an xml-schema I have defined an element (content) that contains mixed
>>data. Specifically contains strings coupled with html tags and the
>>"code" element. Below I have an example of an instance:
>>
>><content>
>> <p>Before the code</p>
>> <code lang="xml">
>> <![CDATA[
>> System.out.println("Hello");
>> ]]>
>> </code>
>> <p>After the code</p>
>></content>
>>
>>I have tried to create a template for the "content" but I cannot do it
>>properly. The xslt applies correctly the template of code but not the
>>remaining data (html script). It does not print the html tags.
>>
>>The generated html returns the following html segment (notice that it
>>also returns the "content" tags):
>>
>><content>
>> Before the code
>>
>> <i>System.out.println("Hello");</i>
>>
>> After the code
>></content>
>>
>>Below I include the xslt template of the content element:
>>
>> <xsl:template match="content">
>> <xsl:copy>
>> <xsl:apply-templates/>
>> </xsl:copy>
>> </xsl:template>
>>
>>Do you know how I will force xslt to print the html tags?
>>
>>Thank you in advance, Kostas
>>
>>
>
>
Re: Problem: Cannot apply template of element with mixed data
Posted by Mukul Gandhi <ga...@gmail.com>.
Hi Kostas,
I think you need xsl:copy-of instead xsl:copy.. xsl:copy does
shallow copy, whereas xsl:copy-of does deep copy..
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates select="content" />
</xsl:template>
<xsl:template match="content">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On Apr 8, 2005 1:31 PM, Kostas Karadamoglou <ka...@yahoo.gr> wrote:
> Hi all,
>
> My problem is the following:
>
> In an xml-schema I have defined an element (content) that contains mixed
> data. Specifically contains strings coupled with html tags and the
> "code" element. Below I have an example of an instance:
>
> <content>
> <p>Before the code</p>
> <code lang="xml">
> <![CDATA[
> System.out.println("Hello");
> ]]>
> </code>
> <p>After the code</p>
> </content>
>
> I have tried to create a template for the "content" but I cannot do it
> properly. The xslt applies correctly the template of code but not the
> remaining data (html script). It does not print the html tags.
>
> The generated html returns the following html segment (notice that it
> also returns the "content" tags):
>
> <content>
> Before the code
>
> <i>System.out.println("Hello");</i>
>
> After the code
> </content>
>
> Below I include the xslt template of the content element:
>
> <xsl:template match="content">
> <xsl:copy>
> <xsl:apply-templates/>
> </xsl:copy>
> </xsl:template>
>
> Do you know how I will force xslt to print the html tags?
>
> Thank you in advance, Kostas
>
>