Subject: Re: [xsl] XML overlap - processing a node-set defined by <start/> and <end/> From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sun, 18 Feb 2007 12:41:28 +0530 |
<?xml version="1.0"?> <ex:x xmlns:ex="http://dummy-ns"> <ex:paragraph> <ex:START/> <ex:span> Some text C.. </ex:span> </ex:paragraph> <ex:paragraph> Some text D.. <ex:END/> <ex:span> Some text F.. </ex:span> </ex:paragraph> </ex:x>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ex="http://dummy-ns" version="1.0">
<xsl:template match="/"> <ex:result> <xsl:apply-templates select="//ex:START" /> </ex:result> </xsl:template>
<xsl:template match="ex:START"> <xsl:call-template name="OutputContent"> <xsl:with-param name="node-set" select="following-sibling::node()[not(self::text() and normalize-space(.) = '')] | ../following-sibling::*/node()[not(self::text() and normalize-space(.) = '')]" /> </xsl:call-template> </xsl:template>
<xsl:template name="OutputContent"> <xsl:param name="node-set" />
<xsl:if test="not($node-set[1]/self::ex:END)"> <xsl:copy-of select="$node-set[1]" /> <xsl:call-template name="OutputContent"> <xsl:with-param name="node-set" select="$node-set[position() > 1]" /> </xsl:call-template> </xsl:if> </xsl:template>
<ex:result xmlns:ex="http://dummy-ns"> <ex:span> Some text C.. </ex:span> Some text D.. </ex:result>
The stylesheet is not rigorously tested. But I feel, you could use this as it is, or perhaps adapt it.
Imagine XML data, where continuous selection of data - randomly made by the user - is being marked by using a <start/> and <end/> element.
For example:
<ex:paragraph> <ex:START/> <ex:span> Some text C.. <ex:span> </ex:paragraph> <ex:paragraph> Some text D.. <ex:END/> <ex:span> Some text F.. <ex:span> </ex:paragraph>
The desired nodes would be <ex:span> Some text C.. <ex:span> Some text D..
Is there an easy way to process this kind of selection with XSLT?
Best regards, Svante
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML overlap - processing , James Fuller | Thread | [xsl] ex of controlling saxon with , James Fuller |
[xsl] Using XSLT 2.0 To Optimize Li, M. David Peterson | Date | [xsl] trying to create repeatable i, Peter Guillam |
Month |