Page 1 of 1

XSL-FO apply templates match HELP A Brother out!

Posted: Mon Nov 06, 2006 12:11 pm
by xml_love_child_2007
Hi all,

i have a xml file like the snippet below and i need to output it using XSL-FO. I need to apply templates to the people/females bit and then to the <h3> element and the <p>.

Snippet from the xml file:

<people>
<females> <h3>Jane<p>Clare<p> Mirna </h3> </females>
</people

Can anyone tell me how to do this, at the moment the text node is just output to the pdf as is, ie. <h3>Jane<p>Clare</p> fMirna </h3>

it would seem that the node is being processed as text and no matching is occuring on the the <h> and <p>

any ideas!?? some code i have so far is (top bit is in a template):

<fo:block>
<xsl:apply-templates select="descr" />
</fo:block>


<xsl:template match="descr" >
<xsl:apply-templates />
</xsl:template>

<xsl:template match="h3">
<fo:inline font-weight="600" font-size="14pt">
aaaaaaaaa<xsl:apply-templates />
</fo:inline>
</xsl:template>

Posted: Mon Nov 06, 2006 1:54 pm
by george
That is because the content of females element is a text node whose content looks like XML. The best thing if you have control over the input is to change the format to give you XML instead of the serialization of that XML fragment. The alternative is to use extension functions to parse that text node content into XML nodes, Saxon for instance has a saxon:parse extension.

Best Regards,
George

Posted: Tue Nov 07, 2006 3:56 am
by xml_love_child_2007
so does xalan/fop support and similiar functionality to this, ie. the parse a text node into a set of nodes? I am new to this so any advice would be great

Posted: Tue Nov 07, 2006 2:09 pm
by sorin_ristache
Hello,

No, Xalan does not have an extension for parsing a text node and building the corresponding tree of XML elements. If you cannot use Saxon which has this extension so you must use Xalan and you want to apply this method of parsing the text node with an instruction of the XSLT stylesheet you have to write the Xalan extension yourself. As George suggested I think it is better to generate XML tags in your XML source where you need XML tags, that is:

Code: Select all

<people>
<females>
<h3>Jane<p/>Clare<p/> Mirna </h3>
</females>
</people>
instead of

Code: Select all

<people>
<females> <h3>Jane<p>Clare<p> Mirna </h3> </females>
</people>

Regards,
Sorin

Posted: Tue Nov 07, 2006 3:04 pm
by xml_love_child_2007
Alright then I have tried to use Saxon and i get a funny error.

Is it possible for someone to explain the steps in using Saxon

xsl:variable name="string"><xsl:value-of select="descr" /></xsl:variable>
<xsl:variable name="rtf"> <xsl:value-of select="saxon:parse($string)"></xsl:value-of> </xsl:variable>
<xsl:value-of select="$rtf"></xsl:value-of>

i get the error -- org.xml.sax.SAXParseException. The markup in the document following the root node must be well formed.

But it is well formed!??

Posted: Tue Nov 07, 2006 3:15 pm
by sorin_ristache
Can you post a small and complete sample of the XML source and the XSL source ? Is the content of the descr element well-formed ?


Regards,
Sorin

Posted: Tue Nov 07, 2006 3:23 pm
by xml_love_child_2007
<descr> <h3>Jane<p>Clare<p> Mirna </h3> </descr>

that is the piece of xml i am trying to figure out

<xsl:variable name="string"><xsl:value-of select="descr" /></xsl:variable>
<xsl:variable name="rtf"> <xsl:value-of select="saxon:parse($string)"></xsl:value-of> </xsl:variable>


not sure where to go from here!?

Posted: Tue Nov 07, 2006 3:29 pm
by sorin_ristache
The content of descr is:

Code: Select all

<h3>Jane<p>Clare<p> Mirna </h3>
and that is not well-formed XML because there are two <p> tags opened and not closed. Maybe it should be

Code: Select all

<h3>Jane<p>Clare</p> Mirna </h3>
in the XML source.


Regards,
Sorin

Posted: Tue Nov 07, 2006 3:41 pm
by xml_love_child_2007
Sorin you awesome person! While the error you pointed out was just a copy and paste error on my behalf, there was a similiar not well formed element... :)

Now how do I continue on ie, I am now getting the output of:

Jane Mirna etc.

but I want to apply templates to that of the h3, any suggestions?

I will work on it now but any help would be grand!