Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] How to use following-sibling & starts-with function in xsl

From: "Michael Kay" <mike@--------.--->
To: <xsl-list@-----.------------.--->
Date: 5/10/2009 8:44:00 AM
Selva,

You'd have a better chance of getting a response if your code was nicely
laid out so that people could read it. Also, using literal result elements
rather than xsl:element and xsl:attribute greatly helps readability.

In your input, the <div class='LegPrelims'> is a child of the <div
class='DocContainer'>, it is not a following sibling.

xsl:when test="(starts-with(p, 'Laid'))" tests whether the first child p
element starts with Laid. If you want to test whether ANY child p element
starts with Laid, use test="p[starts-with(., 'Laid')".

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 
 

> -----Original Message-----
> From: Selva Ganesh [mailto:selvaganesh1985@g...] 
> Sent: 10 May 2009 03:22
> To: xsl-list
> Subject: [xsl] How to use following-sibling & starts-with 
> function in xsl
> 
> Hi All,
> 
> I heartly appreciate.
> 
> I have 3 question:
> 1.	following-sibling function not working in the "si - 
> docid" attribute
> 2.	starts-with function not working in "laid" element
> 3.	choose method want correct (I need single dates 
> element) in my xsl
> repeated the <dates>
> 
> 
> This is my XSL:
> 
> <xsl:template match="div[@class='DocContainer']">
> <xsl:element name="si">
> <xsl:attribute name="docid"><xsl:value-of 
> select="following-sibling::div[@class 
> ='LegPrelims']/h1[@class = 'LegNo'][1]" /></xsl:attribute> 
> <xsl:attribute name="type"><xsl:text>reg</xsl:text></xsl:attribute>
> <xsl:apply-templates></xsl:apply-templates></xsl:element></xsl
> :template>
> <xsl:template match="title"/>
> <xsl:template match="style"/>
> <xsl:template match="div[@class[.='LegPrelims']]">
> <si-begin>
> <xsl:apply-templates></xsl:apply-templates>
> </si-begin>
> </xsl:template>
> <xsl:template match="h1">
> <xsl:element name="si-nos" >
> <xsl:element name="si-year" ><xsl:value-of 
> select="substring-before(., ' ')"/></xsl:element> 
> <si-no><xsl:value-of select="substring-after(., '. 
> ')"/></si-no></xsl:element> </xsl:template> <xsl:template 
> match="div[@class[.='LegDate']]"> <dates> <xsl:choose> 
> <xsl:when test="p='Made'"> <xsl:element 
> name="made"><xsl:attribute name="date"> <xsl:value-of 
> select="p[@class[.='LegDateDate']]"/></xsl:attribute>
> <xsl:value-of 
> select="p[@class[.='LegDateText']]"/></xsl:element></xsl:when>
> <!--<xsl:when test="(starts-with(p, 'Laid'))">--> <xsl:when 
> test="p='Laid before Parliament'"> <xsl:element 
> name="laid"><xsl:attribute name="date"> <xsl:value-of 
> select="p[@class[.='LegDateDate']]"/></xsl:attribute>
> <xsl:value-of 
> select="p[@class[.='LegDateText']]"/></xsl:element></xsl:when>
> <xsl:otherwise>
> <xsl:element name="in-force"><xsl:element 
> name="in-force-text"><xsl:attribute name="date"> 
> <xsl:value-of select="p[@class ='LegDateDate']"/></xsl:attribute>
> <xsl:value-of 
> select="p[@class[.='LegDateText']]"/></xsl:element></xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </dates>
> </xsl:template>
> 
> This my input:
> 
> <div id="ContentMain"><div class="DocContainer"><div 
> class="LegPrelims">
> <h1 class="LegNo">2009 No. 1023</h1>
> <p class="LegSubject">Excise</p>
> <h1 class="LegTitle">The Excise </h1>
> <div class="LegDate">
> <p class="LegDateText">Made</p><p class="LegDateDate">22nd 
> April 2009</p> </div> <div class="LegDate"> <p 
> class="LegDateText">Laid before Parliament</p><p 
> class="LegDateDate">22nd April 2009</p> </div> <div 
> class="LegDate"> <p class="LegDateText">Coming into 
> force</p><p class="LegDateDate">1st June 2009</p> </div> . 
> </div> </div> </div>
> 
> 
> This is expected output
> 
> <si docid="s2009no815" type="reg">
> <si-begin>
> <si-nos>
> <si-year>2009</si-year>
> <si-no>815</si-no>
> </si-nos>
> <subject>
> <subject-text>EXCISE</subject-text>
> </subject>
> <ti al="c">The Excise</ti>
> <dates>
> <made date="20090422">Made</made>
> <laid date="20090422">Laid before Parliament</laid> <in-force 
> date="20090601"><in-force-text>Coming into 
> force</in-force-text> </in-force> </dates> . </si-begin> </si>
> 
> Thanks,
> Selva
> 
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@l...>
> --~--
> 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



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