Using result-document - how can I create a template within?
Here should go questions about transforming XML with XSLT and FOP.
Using result-document - how can I create a template within?
Hi,
I am using result-document to create a number of pages for my site. I am just about to start customizing the styles a lot more to get them looking how I need them. However, I can't work out how to use the templates within the result-document tag. I have posted my code below. You will see that the <html>, <head> and <body> tags are repeated in both result-document sections. I am trying to find a way that I could use a template to create these tags so that there is no need for a duplicate, but can't work out how. The only way I know to use <xsl:apply-templates> is by selecting the names of one of the elements but I wouldn't want to do this in this example. Does anyone know how this is done?
Here's the code appropriate to this question:
I am using result-document to create a number of pages for my site. I am just about to start customizing the styles a lot more to get them looking how I need them. However, I can't work out how to use the templates within the result-document tag. I have posted my code below. You will see that the <html>, <head> and <body> tags are repeated in both result-document sections. I am trying to find a way that I could use a template to create these tags so that there is no need for a duplicate, but can't work out how. The only way I know to use <xsl:apply-templates> is by selecting the names of one of the elements but I wouldn't want to do this in this example. Does anyone know how this is done?
Here's the code appropriate to this question:
Code: Select all
<xsl:template match="/">
<xsl:apply-templates select="//chapter"/>
<xsl:result-document href="new/index.php" format="html">
<html><head><title>Index</title></head>
<body>
<xsl:for-each select="//chapter">
<a href="{abbrev}.php"><xsl:value-of select="title" />
</a><br/>
</xsl:for-each>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="//chapter">
<xsl:variable name="filename" select="concat('new/',abbrev,'.php')" />
<xsl:value-of select="$filename" />
<xsl:result-document href="{$filename}" format="html">
<html><head>
<title>Test results - <xsl:value-of select="title"/></title>
</head><body>
<xsl:value-of select="title"/>
<xsl:apply-templates select="section"/>
</body></html>
</xsl:result-document>
</xsl:template>
Re: Using result-document - how can I create a template within?
Hello,
You can create a template and give it a name, like this for example:
And call it from result-document with <xsl:call-template name="common"/>.
Regards,
Adrian
You can create a template and give it a name, like this for example:
Code: Select all
<xsl:template name="common">
<html>
<head></head>
<body></body>
</html>
</xsl:template>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Re: Using result-document - how can I create a template within?
Cheers for that Adrian. I have tried using call-template but am still unsure exactly how I can use this template for both of my xsl:result-document needs. For example, with your script, I would have:
Is there anyway I would be able to work it so that include this template inside of my two different xsl:result-document tags. Is there a way that I could attach a variable to each of the two different result-document tags and then use xsl:if asking for the name of that variable. What would be the way of doing this? I have been looking through all kinds of manuals for the answer on this but it has not been easy to find!!
Thanks for your help though. It's appreciated!
Code: Select all
<xsl:template name="common">
<html>
<head></head>
<body>
[in the middle here I would want calls to two different templates]
</body>
</html>
</xsl:template>
Thanks for your help though. It's appreciated!
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