Subject: Re: [xsl] Reading Attributes in XSL From: pankaj.ahuja@xxxxxxxxxxxx Date: Tue, 15 Nov 2005 09:39:57 -0700 |
This will exactly tell you what I am trying to do: Problem: XML to break into pages or into tables having 4 records each: <?xml version="1.0" encoding="UTF-8"?> <Person race="Asian" Sex="Male"> <Person1 FirstName="Pankaj" LastName="Ahuja"> <CharateristicsCollection> <Characteristics Profession="Programmer" jobs="3jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> </Characteristics> <Characteristics Profession="Programmer1" jobs="2jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> </Characteristics> <Characteristics Profession="Programmer2" jobs="1jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> </Characteristics> <Characteristics Profession="Programme3r" jobs="3jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> </Characteristics> <Characteristics Profession="Programmer4" jobs="3jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> </Characteristics> <Characteristics Profession="Programmer5" jobs="3jobs"> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> </Characteristics> </CharateristicsCollection> </Person1> </Person> Result desired: 1. Want to break this into table using XSL(XPATH) having 4 records each (Including Attributes of Characteristics as well as Child elements of Characteristics) 2.I want structure like this: Asian Male Pankaj Ahuja Programmer--(This one is the 1st attribute of Characteristics) 6680 S 84121 80000 6681 S 84121 60000 6682 S 84121 70000 (Page Break after this as this shd break after 4 records) 3jobs --(This one is the 2nd attribute of Characteristics) Programmer1--(This one is the 1st attribute of Characteristics) 6680 S 84121 80000 6681 S 84121 60000 (Page Break after this as this shd break after 4 records) 2jobs --(This one is the 2nd attribute of Characteristics) Programmer2 6680 S 84121 80000 1jobs (Page Break after this as this shd break after 4 records) and so on with each page Problem Solving:: Have tried this : CharateristicsCollection/Characteristics/Detail[position() mod 4 = 1] -- -- (. | following-sibling::* |../following-sibling::*/*)[position () <= 4]"> but helps only if XML is like this: <?xml version="1.0" encoding="UTF-8"?> <Person race="Asian" Sex="Male"> <Person1 FirstName="Pankaj" LastName="Ahuja"> <CharateristicsCollection> <Characteristics> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> <Detail Address="6680 S" Zip="84121" Salary="80000"/> <Detail Address="6681 S" Zip="84121" Salary="60000"/> <Detail Address="6682 S" Zip="84121" Salary="70000"/> </Characteristics> </CharateristicsCollection> </Person1> </Person> This works only if there are no multiple Detail collection in separate groups. -------------------------------------------------------------- ------------------------------------- I cannot get this to work where it is needed to first read the first attribute and then all attributes of the child and then back to reading the second attribute of the parent element. Also how to keep track of next items. David Carlisle <davidc@xxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > cc: Subject: Re: [xsl] Reading Attributes in XSL 11/15/2005 09:31 AM Please respond to xsl-list > I am trying to read attributes of current node such that I read the first > Attribute Note that attribute order is stable but implementation defined. What do you mean by "first attribute" ? You can use @*[1] to select the first attribute in document order, but that need not be (and often is not) the first attribute to appear on the element. (XML parsers are not required to report the order in which attributes appear). On the face of it you seem to want <xsl:for-each select="@*[1]|*/@*"> something for first attribute and attributes on children </xsl:for-each> <xsl:for-each select="@*[position()>1]"> something for later attributes </xsl:for-each> David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Reading Attributes in XSL, Jon Gorman | Thread | Re: [xsl] Reading Attributes in XSL, pankaj . ahuja |
Re: [xsl] Reading Attributes in XSL, Jon Gorman | Date | Re: [xsl] Reading Attributes in XSL, pankaj . ahuja |
Month |