1

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">
   <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

2 Answers 2

3

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

For example:

<xsl:element name="@name"><xsl:value-of select="@caption"></xsl:element>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I am new to XSL and never saw this tag
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.