XSL-FO apply templates match HELP A Brother out!
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 7
- Joined: Mon Nov 06, 2006 12:06 pm
XSL-FO apply templates match HELP A Brother out!
Post 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>
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>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
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
Best Regards,
George
George Cristian Bina
-
- Posts: 7
- Joined: Mon Nov 06, 2006 12:06 pm
Post 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
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post 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:
instead of
Regards,
Sorin
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>
Code: Select all
<people>
<females> <h3>Jane<p>Clare<p> Mirna </h3> </females>
</people>
Regards,
Sorin
-
- Posts: 7
- Joined: Mon Nov 06, 2006 12:06 pm
Post 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!??
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!??
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post 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
Regards,
Sorin
-
- Posts: 7
- Joined: Mon Nov 06, 2006 12:06 pm
Post 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!?
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!?
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
The content of descr is:
and that is not well-formed XML because there are two <p> tags opened and not closed. Maybe it should be
in the XML source.
Regards,
Sorin
Code: Select all
<h3>Jane<p>Clare<p> Mirna </h3>
Code: Select all
<h3>Jane<p>Clare</p> Mirna </h3>
Regards,
Sorin
-
- Posts: 7
- Joined: Mon Nov 06, 2006 12:06 pm
Post 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!

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!
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service