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

Re: Generating attributes from the position of an elem

Subject: Re: Generating attributes from the position of an element
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Tue, 1 Jun 2010 13:02:32 +0530
Re:  Generating attributes from the position of an elem
I would have done this as following,

<xsl:template match="node() | @*">
   <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
   </xsl:copy>
</xsl:template>

<xsl:template match="@ID">
   <xsl:attribute name="Id">
      <xsl:value-of select="count(../preceding-sibling::w) + 1" />
   </xsl:attribute>
</xsl:template>

PS: this is not tested.

On Tue, Jun 1, 2010 at 12:22 PM, GC!bor TC3th <roysy@xxxxxxxx> wrote:
> Dear All,
>
> I have the following xml file and wish to generate ID-s based on the
> position to the <w> elements with the following XSL file, however, the
> end result of the ID attribute is always 1, I have no idea why.
>
> The xml file is
>
> <?oxygen
RNGSchema="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all
.rng"
> type="xml"?>
> <?xml-stylesheet type="text/xsl" href="template.xsl"?>
> <text>
> B  B <w ID=" " >car</w>
> B  B <w ID=" ">dog</w>
> B  B <w ID=" ">cat</w>
> B  B <w ID=" ">house</w>
>
> </text>
>
> The XSL file is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> B  B xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0"
> B  B version="2.0" exclude-result-prefixes="tei"
> B  B xpath-default-namespace="http://www.tei-c.org/ns/1.0"
> B  B >
>
>
> B  B <xsl:template match="@*|node()|comment()|processing-instruction()"
> priority="-5">
> B  B  B  B <xsl:copy><xsl:apply-templates
> select="@*|node()|comment()|processing-instruction()"/></xsl:copy>
> B  B  B  B <xsl:apply-templates select="/text/w/@ID"/>
>
> B  B </xsl:template>
>
> <xsl:template match="@ID">
> B  B  B  B  <xsl:attribute name="Id">
> B  B  B  B  B  B <countNo><xsl:value-of select="position()"/></countNo>
>
> B  B  B  B </xsl:attribute>
>
> B  B </xsl:template>
>
> Result:
>
> <?xml version="1.0" encoding="UTF-8"?><?oxygen
>
RNGSchema="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all
.rng"
> type="xml"?><?xml-stylesheet type="text/xsl"
> href="template.xsl"?><text>
> B  B <w Id="1">car</w>
> B  B <w Id="1">dog</w>
> B  B <!-- Why does not increment the number of the ID? B -->
> <w Id="1">cat</w>
> B  B <w Id="1">house</w>
>
> </text>
>
> Thanks,
>
> Gabor



--
Regards,
Mukul Gandhi

Current Thread

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
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.