|
Subject: RE: [xsl] Accessing a node dynamically using XSL From: Florent Georges <darkman_spam@xxxxxxxx> Date: Mon, 16 Jan 2006 18:05:51 +0100 (CET) |
Sumiit Kumar Mukherjee wrote:
> <Name type="String">harry</Name>
> <Subjects type="String">Literature,Fiction</Subjects>
> <Literature type="String">Shakespeare, Woodsworth, Jeffrey
> Archer</Literature>
> <Fiction type="String">Da Vinci Code</Fiction>
> My requirement is like this: First, find out the values in the
> <Subjects> element. For each such value [separated by a comma],
> there will be an element present in the XML
~> cat skm.xml
<root>
<Name type="String">harry</Name>
<Subjects type="String">Literature,Fiction</Subjects>
<Literature type="String">Shakespeare, Woodsworth</Literature>
<Fiction type="String">Da Vinci Code</Fiction>
</root>
~> cat skm.xsl
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="root">
<xsl:apply-templates
select="for $sub in tokenize(Subjects, ', *')
return *[local-name()=$sub]"/>
</xsl:template>
<xsl:template match="*">
<xsl:value-of select="local-name()"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:transform>
~> saxon skm.xml skm.xsl
Literature: Shakespeare, Woodsworth
Fiction: Da Vinci Code
With XSLT 1.0, use a recursive template instead of an XPath 'for'
expression.
--drkm
___________________________________________________________________________
Nouveau : tiliphonez moins cher avec Yahoo! Messenger ! Dicouvez les tarifs exceptionnels pour appeler la France et l'international.
Tilichargez sur http://fr.messenger.yahoo.com
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Accessing a node dynamica, David Carlisle | Thread | [xsl] Multiple input sources from p, rc |
| Re: [xsl] Recursion performance (fi, Mukul Gandhi | Date | Re: [xsl] Extracting an attribute v, Sebastian Tennant |
| Month |