Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2006, 12:46 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bhvijaykumar
Default How can i do this ?

Hi
I have following XML codefragment

<Employee>
<Array length="3">
<ArrayElement>AAAAAA</ArrayElement>
<ArrayElement>BBBBBB</ArrayElement>
<ArrayElement>CCCCCC</ArrayElement>
</Array>
</Employee>

And i want to remove BBBBB from the above and also i want to have the
Array length as 2

ie after transformation i need

<Employee>
<Array length="2">
<ArrayElement>AAAAAA</ArrayElement>
<ArrayElement>CCCCCC</ArrayElement>
</Array>
</Employee>

Can anybody give me sample code how can i do this. I can remove BBBB but dont know how to change the length As i dont know how many such ArrayElements are present.

Thanks In Advance


Vijay
 
Old May 5th, 2006, 02:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try

<xsl:template match="Array">
  <xsl:variable name="retain" select="ArrayElement[not(. = 'BBBBBB')]"/>
  <xsl:attribute name="length">
    <xsl:value-of select="count($retain"/>
  </xsl:attribute>
  <xsl:copy-of select="$retain"/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 29th, 2006, 12:29 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bhvijaykumar
Default

Thanks for the code
Actually i wanted to remove all the entries which has some common string
ie i wanted to remove all the elements which are ending with BB / starting with AA for example

How can i do that

Thanks


Vijay









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.