Position of child element within mixed content
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 80
- Joined: Wed Jan 14, 2009 12:50 pm
Position of child element within mixed content
I have data like the following (example 1):
<a>text <b>more text</b> text</a>
Sometimes the <b> child element occurs right at the start of the parent <a> (example 2):
<a><b>more text</b> text</a>
or right at the end (example 3):
<a>text <b>more text</b></a>
I want a template to match "a/b" which will let me treat these three scenarios differently; specifically I want to be able to replace the <b> child with different (or no) text depending on whether it is in the middle (as in 1) or at the start (2) or the end (3). For instance, I might want the result to be:
1: <a>text XXXXX text</a>
2: <a> text</a>
3: <a>text YYY</a>
I can do 1 easily:
<xsl:template match="a/b"><xsl:text>XXXXX</xsl:text></xsl:template>
But I'm not sure how to modify this to do 2 and 3. I guess this is easy, but I can't quite work out how to do it.
<a>text <b>more text</b> text</a>
Sometimes the <b> child element occurs right at the start of the parent <a> (example 2):
<a><b>more text</b> text</a>
or right at the end (example 3):
<a>text <b>more text</b></a>
I want a template to match "a/b" which will let me treat these three scenarios differently; specifically I want to be able to replace the <b> child with different (or no) text depending on whether it is in the middle (as in 1) or at the start (2) or the end (3). For instance, I might want the result to be:
1: <a>text XXXXX text</a>
2: <a> text</a>
3: <a>text YYY</a>
I can do 1 easily:
<xsl:template match="a/b"><xsl:text>XXXXX</xsl:text></xsl:template>
But I'm not sure how to modify this to do 2 and 3. I guess this is easy, but I can't quite work out how to do it.
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Position of child element within mixed content
You can use something like below
Best Regards,
George
Code: Select all
<xsl:template match="a/b[not(preceding-sibling::node())]" priority="10">
<xsl:text>FIRST</xsl:text>
</xsl:template>
<xsl:template match="a/b[not(following-sibling::node())]" priority="5">
<xsl:text>LAST</xsl:text>
</xsl:template>
<xsl:template match="a/b">
<xsl:text>MIDDLE</xsl:text>
</xsl:template>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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