Escaping characters in text output
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Mon Sep 29, 2008 2:32 pm
Escaping characters in text output
Hi,
I'm trying to convert a convert a Office XML-file into a tagged text file. The text file uses a special syntax, similar to a flat XML-file (but it's not valid XML). That means that characters such as < and > have to be escaped in the output.
"<w:t>Some <tagged> text</w:t>" is now converted into "<tag:type>Some <tagged> text<tag:>" in the output. The wanted result is "<tag:type>Some \<tagged\> text<tag:>".
Any help on how I could accomplish this is much appreciated.
Eivind
I'm trying to convert a convert a Office XML-file into a tagged text file. The text file uses a special syntax, similar to a flat XML-file (but it's not valid XML). That means that characters such as < and > have to be escaped in the output.
"<w:t>Some <tagged> text</w:t>" is now converted into "<tag:type>Some <tagged> text<tag:>" in the output. The wanted result is "<tag:type>Some \<tagged\> text<tag:>".
Any help on how I could accomplish this is much appreciated.
Eivind
-
- Posts: 3
- Joined: Fri Oct 17, 2008 11:49 am
-
- Posts: 6
- Joined: Mon Sep 29, 2008 2:32 pm
Re: Escaping characters in text output
Just a followup with my solution, that also supports regexp search and replace.
ITT_SEARCH_REPLACE.xml:
Code: Select all
<xsl:template name="filter_strings">
<xsl:param name="input_text" />
<xsl:param name="search" select="document('ITT_SEARCH_REPLACE.xml')/*/string_replacement/search" />
<xsl:variable name="replaced_text">
<xsl:value-of select="lpp:search-and-replace($input_text, $search[1]/find, $search[1]/replace)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$search[2]">
<xsl:call-template name="filter_strings">
<xsl:with-param name="input_text" select="$replaced_text" />
<xsl:with-param name="search" select="$search[position() > 1]" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$replaced_text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="lpp:search-and-replace">
<xsl:param name="input"/>
<xsl:param name="search-string"/>
<xsl:param name="replace-string"/>
<xsl:sequence select="replace($input, $search-string, $replace-string)"/>
</xsl:function>
Code: Select all
<root>
<string_replacement>
<search>
<find>></find>
<replace>\\></replace>
</search>
<search>
<find><</find>
<replace>\\<</replace>
</search>
</string_replacement>
</root>
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