Newbie: XSLT variables?
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Mon Sep 29, 2008 2:32 pm
Newbie: XSLT variables?
Hi,
I'm new to XSLT and have a problem with using data from a template in another one.
The input (word 2007):
Output should be (indesign tagged text):
I'm able to get the first part right (<pstyle:MyStyle>), but cannot figure out how to save the information in the w:b-element for later use in the w:t-element. All these elements can contain lots of other elements. Sometimes there are w:b, and sometimes there are others, so I cannot "hard code" xslt.
I'm greateful for any help!
Eivind
I'm new to XSLT and have a problem with using data from a template in another one.
The input (word 2007):
Code: Select all
<w:p>
<w:pPr>
<w:pStyle w:val="MyStyle"/>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Some bold text</w:t>
</w:r>
</w:p>
Code: Select all
<pstyle:MyStyle><cstyle:Bold>Some bold text<cstyle:>
I'm greateful for any help!
Eivind
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Newbie: XSLT variables?
Hi Eivid,
It is hard to give you a general solution but, for your example (adding also the namespace declaration):
you can get the desired output with a stylesheet like below:
Best Regards,
George
It is hard to give you a general solution but, for your example (adding also the namespace declaration):
Code: Select all
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:pPr>
<w:pStyle w:val="MyStyle"/>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Some bold text</w:t>
</w:r>
</w:p>
Code: Select all
<?xml version="1.1" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="w:pStyle">
<xsl:text><pstyle:</xsl:text>
<xsl:value-of select="@w:val"/>
<xsl:text>></xsl:text>
</xsl:template>
<xsl:template match="w:r/w:rPr/w:b">
<xsl:text><cstyle:Bold></xsl:text>
<xsl:apply-templates select="../following-sibling::*" mode="content"/>
<xsl:text><cstyle:></xsl:text>
</xsl:template>
<xsl:template match="w:t" mode="content">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
George
George Cristian Bina
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