Re: [xsl] Attribute values to string/text

Subject: Re: [xsl] Attribute values to string/text
From: Jeff Sese <jeferson.sese@xxxxxxxxxxxx>
Date: Wed, 9 Apr 2008 15:35:57 +0800
You need to apply templates to elements that contains the dummy attributes, something like:

<xsl:template match="*[@dummy]">
	<xsl:copy>
		<xsl:apply-templates select="@*"/>
		<xsl:value-of select="@dummy"/>
	</xsl:copy>
</xsl:template>
<xsl:template match="@dummy"/> <!-- to remove the dummy attribute -->

for making the journalcode and issn as a child of meta element, apply templates to these elements inside the copy template of the meta element:

<xsl:template match="meta">
	<xsl:copy>
		<xsl:apply-templates select="/article/journalcode|/articel/issn"/>
	</xsl:copy>
</xsl:template>

* not tested

-- Jeff

On 04 9, 08, at 2:39 PM, Pankaj Chaturvedi wrote:

Hello all,

I am trying to convert all the "dummy" attribute name to its corresponding
element text in a generic way. Secondly I also need to define elements
<journalcode>, and both <issn> to be appear as child element of <meta>
(though I've not tested it yet). Below is what I've tried to do but I am
able to pick the value of @dummy resulting into <issn type="print"></issn>
and so on.


Can somebody shed some light on it, where I am being wrong.


XML ===== <article> <meta/> <journalcode dummy="CIJB"/> <issn type="print" dummy="0269-2171"/> <issn type="electronic" dummy="1465-3486"/> </article>


Desired Output ============

<article>
<meta>
<journalcode>CIJB</journalcode>
<issn type="print">0269-2171</issn>
<issn type="electronic">1465-3486</issn>
</meta>
</article>


Stysheet ========


<xsl:template match="*|@*"> <xsl:choose> <xsl:when test="name()='dummy'"> <xsl:copy-of select="@*"/> <xsl:value-of select="string(./@dummy)"/> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="text()|*|@*"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template>


Best,


Pankaj Chaturvedi

====================================================================== ======
================



Confidentiality Notice:" This message and any attachment(s) contained here are information that is confidential, proprietary to IDS Infotech Ltd. and its customers. Contents may be privileged or otherwise protected by law. The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer."


Jeferson L. Sese jeferson dot sese at asiatype dot com Asiatype Incorporated Suite 114 Columbia Tower, Ortigas Ave. Greenhills, Mandaluyong City 1550 Philippines

Current Thread