OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   XSLT 2.0: Definition of a structure and its use

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: XSLT 2.0: Definition of a structure and its use
  • From: "Agnisys Technology \(P\) Ltd." <agnisys@yahoo.com>
  • Date: Wed, 14 Sep 2005 06:49:22 -0700 (PDT)
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ogdGJ3h6MfePReYhxKPSD6uSSLfzFPEOfwDoOwUMZvWTG/v7ieT2nBpvaGfyOnF7K5xt2WkdU50mayZwovotJGMwBT2QTiNkoCafFNSXyJZArhPS3t6TLf/1h8UcoK/Sk/01UZQ78wbU80HNjNDItfRwLOSdpOUq3O+IrowgqIg= ;
  • In-reply-to: <7d645304050914000219222c32@mail.gmail.com>

Hi all,
  I'm trying to emulate a definition of a structure and a call to the definition in XML. I'm
having trouble getting the required output. (Note: this message was posted on the XSL list, but I
don't have a solution yet).

Input XML is :
<a>
    <b offset="5">
         <reg>reg_1</reg>
        <reg>reg_2</reg>
        <reg href="REGDEF1"></reg>  <!-- this is the call to a structure -->
        <reg>reg_3</reg>
     </b>
  
    <!-- this is the definition of the structure -->
    <regdef name="REGDEF1">
          <reg>reg_10</reg>
         <reg>reg_20</reg>
     </regdef>
 </a>
  
XSLT is :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="reg[@href]">
        <xsl:variable name="reg_href">
            <xsl:copy-of select="//regdef[@name=current()/@href]"/>
        </xsl:variable>
        <xsl:apply-templates select="$reg_href/*"/>
    </xsl:template>
    
    <xsl:template match="regdef"/>
    
    <xsl:template match="reg">
        <br/>Register : <xsl:value-of select="."/>
        Offset = <xsl:value-of select="../@offset"/>
        Prev-Sibling count = <xsl:value-of select="count(preceding-sibling::reg)"/>
    </xsl:template>

</xsl:stylesheet>

Output is : 

Register : reg_1 Offset = 5 Prev-Sibling count = 0 
Register : reg_2 Offset = 5 Prev-Sibling count = 1 
Register : reg_3 Offset = 5 Prev-Sibling count = 3 

I want the output to say:
Register : reg_1 Offset = 5 Prev-Sibling count = 0 
Register : reg_2 Offset = 5 Prev-Sibling count = 1 
Register : reg_10 Offset = 5 Prev-Sibling count = 2 
Register : reg_20 Offset = 5 Prev-Sibling count = 3 
Register : reg_3 Offset = 5 Prev-Sibling count = 4 

Thanks,
Anupam.




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS