tags:

views:

25

answers:

2

Hi,

Take the below xml

<?xml version="1.0"?>
<?xml-stylesheet href="desktop.xsl" type="text/xsl"?>
<desktop>
  <tag name="h1" caption="hello"/>
</desktop>

I have an XSLT that will take the name attribute of the tag element and create the appropriate html element

Snippet from the xsl

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
   <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"/> 

   <xsl:template match="tag">
    <{@name}>{@caption}</{@name}>
  </xsl:template>
</xsl:stylesheet>

which of course is not working, due to the < > characters (I suppose)

How can I come around it?

Thanks

+3  A: 

You will need to use <xsl:element>. See here.

For example:

<xsl:element name="@name"><xsl:value-of select="@caption"></xsl:element>
Jake
Thanks a lot. I am new to XSL and never saw this tag
Thomas
No worries, glad I could help!
Jake
A: 

Use <xsl:element> instead which will create a new node. For example, I've once used the following code to create automatically nested headings in HTML:

<xsl:variable name="extlevel" select="count(ancestor::External[not(@link)])"/>   
<xsl:element name="h{$extlevel + 2}"><xsl:value-of select="@name"/></xsl:element>
Joey