xslt - Change output XML values using XSL -


i want output xml have different values. have table made.

lets there many students..

input xml

<?xml version="1.0" encoding="utf-8"?> <person>         <lookuptable>           <name first="jen" ori="jenny" />           <name first="sam" ori="sammy" />         </lookuptable>     <student>         <info name="jen" age="20" class="c" />     </student>     <student>         <info name="sam" age="21" class="b" />      </student>  </person> 

required output

<?xml version="1.0" encoding="utf-8"?> <person>         <lookuptable>           <name first="jen" ori="jenny" />           <name first="sam" ori="sammy" />         </lookuptable>     <student>         <info name="jenny" age="20" class="c" />     </student>     <student>         <info name="sammy" age="21" class="b" />      </student>  </person> 

how can jenny,sammy, etc lookuptable?? meaning each place jen occurs should use jenny table. im not sure how write xsl.

define key, use identity transformation template plus template attribute:

<xsl:key name="k1" match="lookuptable/name" use="@first"/>   <xsl:template match="@* | node()">   <xsl:copy>     <xsl:apply-templates select="@* , node()"/>   </xsl:copy> </xsl:template>   <xsl:template match="student/info/@name">   <xsl:attribute name="{name()}" select="key('k1', .)/@ori"/> </xsl:template> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -