Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] automatic creation of nested elements

From: "Ganesh Babu N" <nbabuganesh@--------->
To:
Date: 12/1/2008 11:36:00 AM
Input XML:

   <map>
      <source>bib-reference</source>
      <source>@id</source>
      <target>reference/citation</target>
      <target>@id</target>
   </map>

Required output:
<xsl:template match="bib-reference">
      <xsl:element name="reference">
        <xsl:element name="citation">
         <xsl:attribute name="id">
            <xsl:value-of select="@id"/>
         </xsl:attribute>
         <xsl:apply-templates/>
      </xsl:element>
   <xsl:element>
 </xsl:template>

My XSLT:
<xsl:template match="map">
<xsl:when test="count(child::*) &gt; 3 and not(starts-with(source,'@'))">
				<mac:template match="{source[1]}">
                                   <xsl:variable name="nestedele"
select="tokenize(target[1],'/')"/>
                                      <xsl:for-each select="$nestedele">
                                          <xsl:variable name="tem" select="."/>
                                		<mac:element name="{$tem}">
						<xsl:for-each select="target">
							<xsl:variable name="pos" select="position()"/>
							<xsl:if test="not(position()=1) and exists(../source[2])">
								<mac:attribute name="{substring-after(.,'@')}">
									<mac:value-of select="{../source[$pos]}"/>
								</mac:attribute>
							</xsl:if>							
						</xsl:for-each>
						<mac:apply-templates/>
					</mac:element>
                                   </xsl:for-each>
				</mac:template>
			</xsl:when>
</xsl:template>

This will create one element after the other but it won't create the
nested one. In a result for bib-reference, two elements will be
created with same content. Which is a wrong one. Please guide me how
to generate the nested element structure.

Regards,
Ganesh


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent