Template match result to variable?
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 8
- Joined: Wed Feb 19, 2020 10:52 pm
Template match result to variable?
Post by GregWait42 »
Within a dita to text plugin, I'm splitting up a lenghty element using in the dita docs. The plugin then uses to break it up at those processing instructions.
What I'd like to do (and have so far failed to find a way to do) is take each result from the template "matching" and populate a variable with the result. My plugin spits out the separate "pieces", but I don't know how to take that and put it in a variable. The ultimate goal is to be able to get the string-length of each segment and determine when one is long enough that I need to force a wrap and create an indent for the wrapped segment.
It seems like this should be simple, but my many attempts have yielded an empty variable every time. Any help would be appreciated. - G
Code: Select all
<?linebreak?>
Code: Select all
<xsl:template name="lbremain" match="processing-instruction()[name() = 'linebreak']">
What I'd like to do (and have so far failed to find a way to do) is take each result from the template "matching" and populate a variable with the result. My plugin spits out the separate "pieces", but I don't know how to take that and put it in a variable. The ultimate goal is to be able to get the string-length of each segment and determine when one is long enough that I need to force a wrap and create an indent for the wrapped segment.
It seems like this should be simple, but my many attempts have yielded an empty variable every time. Any help would be appreciated. - G
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Template match result to variable?
Hi Greg,
When you match on the processing instruction, you can only control the output underneath it, you cannot control the output of text fragments before and after it.
What you probably need to do is to match the element which contains the processing instruction and in this way have access to the entire set of text nodes and processing instructions in the element.
Something like:
Regards,
Radu
When you match on the processing instruction, you can only control the output underneath it, you cannot control the output of text fragments before and after it.
What you probably need to do is to match the element which contains the processing instruction and in this way have access to the entire set of text nodes and processing instructions in the element.
Something like:
Code: Select all
<!-- Match any XML element which has a linebreak PI as a direct child-->
<xsl:template match="*[processing-instruction()[name() = 'linebreak']]">
<!-- Copy element as it is -->
<xsl:copy>
<!-- Copy attributes as they are -->
<xsl:apply-templates select="@*"/>
<xsl:for-each select="node()">
<xsl:if test="name() = 'linebreak'">
<!-- This is a processing instruction, you can use the preceding-sibling:: to look at the text before it for example-->
</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “DITA (Editing and Publishing DITA Content)”
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