Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] automatic creation of nested elements

From: "Ganesh Babu N" <nbabuganesh@--------->
To:
Date: 12/4/2008 6:16:00 AM
Dear all,

I am facing two problems in the given stylesheet.

1. <xsl:apply-templates/> is coming in both the elements resulting
duplication of the content.
2. multiple attributes are not getting created. Only single
attributing is getting created.

Please guide me how to achieve the above two points.

Regards,
Ganesh


On Mon, Dec 1, 2008 at 8:22 PM, Vasu Chakkera <vasucv@xxxxxxxxx> wrote:
> Try the below. ( i just carried it along the way of creating the
> children recursively from your target. add your attributes etc as
> necessary ). just changed from where you had a for-each. Dint check
> the other parts of your code. The below produces the result you
> wanted.
>
> <xsl:template match="map">
>                <xsl:if test="count(child::*) &gt; 3 and not(starts-with(source,'@'))">
>                        <mac:template match="{source[1]}">
>                                <xsl:variable name="nestedele"
> select="tokenize(target[1],'/')"/>
>                                <xsl:call-template name="buildtree">
>                                        <xsl:with-param name="position" select="1"/>
>                                </xsl:call-template>
>                        </mac:template>
>                </xsl:if>
>        </xsl:template>
>        <xsl:template name="buildtree">
>                <xsl:param name="position"/>
>                <xsl:variable name = "element" select="tokenize(target[1],'/')[$position]"/>
>                <xsl:if test = "string($element)">
>                        <mac:element name="{$element}">
>                                <xsl:if test="not($position = 1) and exists(source[2])">
>                                        <mac:attribute name="{substring-after(target[$position],'@')}">
>                                                <mac:value-of select="{source[$position]}"/>
>                                        </mac:attribute>
>                                </xsl:if>
>                                <xsl:call-template name="buildtree">
>                                        <xsl:with-param name="position" select="$position +1"/>
>                                </xsl:call-template>
>                                 <mac:apply-templates/>
>                        </mac:element>
>                </xsl:if>
>        </xsl:template>
>
> hth
> Vasu C
>
> 2008/12/1 Ganesh Babu N <nbabuganesh@xxxxxxxxx>:
>> 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
>>
>>
>
>
>
> --
> Vasu Chakkera
> Numerical Algorithms Group Ltd.
> Oxford
> www.vasucv.com


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