Reputation: 13839
My client is requesting something very special. Let's take the following XML as an example:
<?xml version="1.0"?>
<article>
<paragraph>
<w p='0'>This</w>
<w p='1'>is</w>
<w p='2'>the</w>
<w p='3'>first</w>
<w p='4'>paragraph</w>
<w p='p'>.</w>
</paragraph>
<paragraph>
<w p='0'>This</w>
<w p='1'>is</w>
<w p='2'>the</w>
<w p='3'>second</w>
<w p='4'>paragraph</w>
<w p='p'>.</w>
</paragraph>
</article>
My client wants to "fold" all words, but not the folding we technical guys mean. What they want is hide the word node info except the word itself, so after their meaning of "folding", it should look like:
<?xml version="1.0"?>
<article>
<paragraph>This is the first paragraph.</paragraph>
<paragraph>This is the second paragraph.</paragraph>
</article>
What I'm talking about is just the look-n-feel, not the underlying content, which should not be changed through this folding. (EDIT) However, the user is still able to select a word, and change its attribute or the word itself (somehow via an application interface),
My question is, are there any ready-made libraries (I'm using C#) or apps specializing this kind of requirement?
Thanks.
Peter
Upvotes: 0
Views: 64
Reputation: 163418
There's nothing at all "special" in this requirement. It's the kind of routine processing that is done using XSLT thousands of times a day.
Its hard to deduce the transformation rules from your example, in particular knowing exactly where spaces should be inserted. You've inserted a space before every word except the first and the one that just contains ".". If that's really the rule, then your transformation would look like this:
<xsl:transform match="paragraph">
<paragraph><xsl:apply-templates/></paragraph>
</xsl:transform>
<xsl:template match="w[1]" priority="3">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="w[.='.']" priority="2">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="w" priority="1">
<xsl:value-of select="concat(' ', .)"/>
</xsl:template>
In practice you may well need additional rules for other things that crop up in your data.
Upvotes: 1