Submitted Jun 03 by Larisa Kharchuk
Composite.Xslt.Extensions.MarkupParser provides following functions that parse encoded XML documents or XHTML fragments into nodes. Use this extension when you have XML or XHTML as a string and need to copy it to the output or do transformations:
· ParseWellformedDocumentMarkup(String wellformedMarkupString)
The function return XPathNavigator
· ParseXhtmlBodyFragment(String xhtmlBodyFragmentString)
The function return XPathNavigator
To call these methods make the following steps:
1. Go to Administration part | Functions
2. Add new XSLT function with following parameters:
Settings tab:
Name - the function should be called intuitive understanding like "NavigationPath"
Namespace -the namespace should display function’s purpose like "Composite.Pages"
Description -function description
Output type - should be "XHTML"
Input Parameters
No parameters
Function calls
Add new function | Composite | Xslt | Extensios | MarkupParser
Template
Add new namespace “#MarkupParserExtensions”, where "mp" - can be any name
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl in" |
Call methods
|
<xsl:value-of select="mp:ParseXhtmlBodyFragment('<el>1</el><el>2</el>')"/> <xsl:value-of select="mp:ParseWellformedDocumentMarkup('<test><item>1</item><item>2</item></test>')"/> //will return 12 |
What does "well-formed" mean?
The concept of a well-formed document is something that is really new in XML. A document that is well-formed is easy for a computer program to read, and ready for network delivery.
Specifically, in a well-formed document:
- All the begin-tags and end-tags match up
- Empty tags use the special XML syntax (e.g. <empty/>)
- All the attribute values are nicely quoted (e.g. <a href="http://www.test.com/xml.html">)
- All the entities are declared (entities are re-usable chunks of data, much like macros, part of XML's inheritance from SGML).
Preview
In preview mode result will be displayed in HTML format
3. Press “Save” button
4. Edit Page or Template
5. At content area click/right click on Insert button/link | Functions | select created functions
6. Press “OK” button
7. Save changes