[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT 2.0: Definition of a structure and its use

  • To: xml-dev@l...
  • Subject: XSLT 2.0: Definition of a structure and its use
  • From: "Agnisys Technology \(P\) Ltd." <agnisys@y...>
  • 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@m...>

definition of a structure
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 

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.