0
votes

XML:

<root>
 <param name="a">valueOfA</param>
 <param name="b">valueOfB</param>
 <param name="c">valueOfC</param>    
</root>

I need to create param for each param node in xml.

So the expected result:

<xsl:param name="a" select="valueOfA" />
<xsl:param name="b" select="valueOfB" />
<xsl:param name="c" select="valueOfC" />

~ Edit:

Made a mistake, I need an actual xslt param, so it will be usable later in code. fixed above.

~ Edit:

XSLT 1.0 required

~ Edit:

Main issue is to make name of the xsl:param from xml value As below is invalid:

<xsl:param name="{@name}" />

Or variable.

2
If you are making substantial updates to your question, please inform anyone who's already answered - like me :) - by commenting on their answer, so they know to update it. - wst

2 Answers

0
votes
<xsl:template match="root">
  <xsl:copy>
    <xsl:apply-templates select="param"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="param">
  <param name="{ ./@name }" select="{ string(.) }"></param>
</xsl:template>
0
votes

From your edits it appears you are looking for a way to use one XSLT to create another. In order to create elements in the xsl: namespace you need to either use <xsl:element> or use the namespace aliasing facility

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
     xmlns:xslo="urn:xsl-output" exclude-result-prefixes="xslo">
  <xsl:namespace-alias stylesheet-prefix="xslo" result-prefix="xsl" />

  <xsl:template match="root">
    <xslo:stylesheet version="1.0">
      <xsl:apply-templates select="param" />
    </xslo:stylesheet>
  </xsl:template>

  <xsl:template match="param">
    <xslo:param name="{@name}" select="{.}" />
  </xsl:template>
</xsl:stylesheet>

Elements prefixed xslo: in the stylesheet become xsl: in the output document (which itself is another stylesheet).