Convert element name to text
Here should go questions about transforming XML with XSLT and FOP.
			- 
				ted
 - Posts: 2
 - Joined: Fri May 16, 2008 1:31 am
 
Convert element name to text
Hi,
I'm hoping someone might be kind enough to tell me how to convert an element name to text.
A contrived, but simple example:
<LIST>
<Color>Blue</Color>
<Size>Small</Small>
</LIST>
converted to:
<LIST>
<ATTRIBUTE>
<TYPE>Color</TYPE>
<VALUE>Blue<VALUE>
</ATTRIBUTE>
<ATTRIBUTE>
<TYPE>Size</TYPE>
<VALUE>Small</VALUE>
</ATTRIBUTE>
</LIST>
Thanks very much,
T
			
			
									
									
						I'm hoping someone might be kind enough to tell me how to convert an element name to text.
A contrived, but simple example:
<LIST>
<Color>Blue</Color>
<Size>Small</Small>
</LIST>
converted to:
<LIST>
<ATTRIBUTE>
<TYPE>Color</TYPE>
<VALUE>Blue<VALUE>
</ATTRIBUTE>
<ATTRIBUTE>
<TYPE>Size</TYPE>
<VALUE>Small</VALUE>
</ATTRIBUTE>
</LIST>
Thanks very much,
T
- 
				Radu
 - Posts: 9547
 - Joined: Fri Jul 09, 2004 5:18 pm
 
Re: Convert element name to text
Hi Ted,
Here is a small XSL sample to get you going:
Notice the local-name method used to get the node local name.
You can also use the node-name method to get the whole tag name (with prefix).
Regards,
Radu
			
			
									
									Here is a small XSL sample to get you going:
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <LISTS>
            <xsl:apply-templates/>
        </LISTS>
    </xsl:template>
    <xsl:template match="LIST">
        <ATTRIBUTE>
            <TYPE><xsl:value-of select="local-name(Color)"/></TYPE>
            <VALUE>Blue</VALUE>
        </ATTRIBUTE>
        <ATTRIBUTE>
            <TYPE><xsl:value-of select="local-name(Size)"/></TYPE>
            <VALUE>Small</VALUE>
        </ATTRIBUTE>
    </xsl:template>
</xsl:stylesheet>
You can also use the node-name method to get the whole tag name (with prefix).
Regards,
Radu
Radu Coravu 
<oXygen/> XML Editor
http://www.oxygenxml.com
						<oXygen/> XML Editor
http://www.oxygenxml.com
			
				Jump to
				
			
		
			
			
	
	- Oxygen XML Editor/Author/Developer
 - ↳ Feature Request
 - ↳ Common Problems
 - ↳ DITA (Editing and Publishing DITA Content)
 - ↳ Artificial Intelligence (AI Positron Assistant add-on)
 - ↳ SDK-API, Frameworks - Document Types
 - ↳ DocBook
 - ↳ TEI
 - ↳ XHTML
 - ↳ Other Issues
 - Oxygen XML Web Author
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Content Fusion
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen JSON Editor
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen PDF Chemistry
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Feedback
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen XML WebHelp
 - ↳ Feature Request
 - ↳ Common Problems
 - XML
 - ↳ General XML Questions
 - ↳ XSLT and FOP
 - ↳ XML Schemas
 - ↳ XQuery
 - NVDL
 - ↳ General NVDL Issues
 - ↳ oNVDL Related Issues
 - XML Services Market
 - ↳ Offer a Service