Need variable value as element name using XSLT -


i converting 1 format of xml , need insert element , name value of variable. example, trying statements below using xslt, getting error processor saying element name invalid.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"             xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">      <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no" omit-xml-declaration="no"/>      <xsl:variable name="i" select="i"/>     <xsl:variable name="b" select="b"/>     <xsl:variable name="u" select="u"/>     <xsl:variable name="s" select="s"/>     <xsl:variable name="r" select="r"/>     <xsl:variable name="m" select="m"/>     <xsl:variable name="n" select="n"/>  <xsl:template match="/|comment()|processing-instruction()">     <xsl:copy>       <xsl:apply-templates/>     </xsl:copy> </xsl:template>  <xsl:template match="*">     <xsl:element name="{local-name()}">       <xsl:apply-templates select="@*|node()"/>     </xsl:element> </xsl:template>  <xsl:template match="@*">     <xsl:attribute name="{local-name()}">       <xsl:value-of select="."/>     </xsl:attribute> </xsl:template>      <xsl:template match="//w:r">         <xsl:if test="not(./descendant::w:i)">          <xsl:variable name="i">0</xsl:variable>                     </xsl:if>         <xsl:if test="not(./descendant::w:b)">          <xsl:variable name="b">0</xsl:variable>                     </xsl:if>         <xsl:if test="not(./descendant::w:u)">          <xsl:variable name="u">0</xsl:variable>                     </xsl:if>         <xsl:if test="not(./descendant::w:caps)">          <xsl:variable name="c">0</xsl:variable>                     </xsl:if>          <xsl:if test="not(contains($i,'0'))">             <xsl:variable name="r" select="$i"></xsl:variable>         <xsl:text>karthikk</xsl:text>         </xsl:if>         <xsl:if test="not(contains($b,'0'))">         <xsl:variable name="m" select="$r+$b"></xsl:variable>         </xsl:if>         <xsl:if test="not(contains($u,'0'))">         <xsl:variable name="n" select="$m+$u"></xsl:variable>         </xsl:if>         <xsl:copy namespaces="no"><xsl:apply-templates/></xsl:copy> <!--        <xsl:element name="{local-name(.)}"><xsl:element><xsl:value-of select="$n"/><xsl:apply-templates/></xsl:element></xsl:element>-->     </xsl:template>   </xsl:stylesheet> 

how can output element name using xslt variable?

it possible construct element name defined dynamically value of variable:

<xsl:element name="{$vvar}">3</xsl:element> 

if string value of variable $vvar happens "hello", above produces:

<hello>3</hello> 

however, if string value of variable $vvar happens "123" error raised string "123" isn't legal name in xml.

it isn't clear in code you'd construct element dynamically (and there other errors in code), use above rules/example , construct elements described.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -