0

Got the following xml file

<persns> 
 <prsn> 
  <fname>Smith</fname> 
  <lname>Milton</lname> 
  <age>44</age> 
  <addrss>5th summer st, mntb</addrss>
  <city>Portland</city>
 </prsn>
 <prsn> 
  <fname>Ken</fname> 
  <lname>Jackson</lname> 
  <age>37</age> 
  <addrss>19th Penfield ave, brtcl</addrss>
  <city>Kelowna</city>
 </prsn>
 <prsn> 
  <fname>Susan</fname> 
  <lname>Arkland</lname> 
  <age>48</age> 
  <addrss>34th Mansfield st, sgtp</addrss>
  <city>Raleigh</city>
 </prsn>
 <prsn> 
  <fname>George</fname> 
  <lname>Bond</lname> 
  <age>35</age> 
  <addrss>5th drive, mntb</addrss>
  <city>Albany</city>
 </prsn>
 <prsn> 
  <fname>Ron</fname> 
  <lname>Davis</lname> 
  <age>37</age> 
  <addrss>12th Greenfield ave, brtcl</addrss>
  <city>Pheonix</city>
 </prsn>
 <prsn> 
  <fname>Marie-Ann</fname> 
  <lname>Spencer</lname> 
  <age>48</age> 
  <addrss>273 Simpson square</addrss>
  <city>Oklahoma</city>
 </prsn>
<prsn> 
  <fname>David</fname> 
  <lname>Rhonson</lname> 
  <age>45</age> 
  <addrss>255 Lakeland Terrace, mi</addrss>
  <city>Livonia</city>
 </prsn>
</persns>

and, again for paging purposes need the children nodes display limited at just 3 items per page. And for this one has to have somehow two (or perhaps one..) templates. First one, like this

 <xsl:variable name="frme" select="3" />
 <xsl:template match ="persns">
<xsl:apply-templates select="prsn[position()mod$frme=1]"/>
</xsl:template>

and the second, something like this (which's not working..)

<xsl:template match="/prsn">
<!-- do some html table formatting and display those particular prsn's name, age etc -->
</xsl:template>

Because only the first template is actually fired and sequentially displays (almost correctly) all of the 8 or 9 prsn node details, the second template is simply ignored (which is right). Question is how one is supposed format displaying - at one time - that limited number of persons children nodes along with theirs sub-characteristics: age, address, city etc. Already asked this kind of question, but that working solution ain't quite working for me through that old xslt 2 frameless processor. I strongly need this sort of solution till I switch over Saxon processor and setting over that previously mentioned answer. Thank you very much in advance.

mirexS
  • 27
  • 4
  • `match="/prsn"` matches a root element named `prsn`, i.e. a child element named `prsn` of the document. Your root element is named `persns` so `/prsn` doesn't make any sense for the input sample you have posted, it is never matching anything in that sample, independent of other templates. – Martin Honnen Jan 22 '23 at 21:05
  • And of course, if you want to have two templates for the same element or node and want to use both, use modes e.g. `xsl:template match="prsn"` and `xsl:template match="prsn" mode="item"`. – Martin Honnen Jan 22 '23 at 21:14
  • Through the first template I'm selecting a certain number of nodes to be displayed. And by some other template I need a way that WITHIN that previous selection to format display of those 3 (or whatever variable number is) nodes... Or.. if this could be done within a single template. Need to use of some variable which construct that selected nodes fragment tree (in xslt 2 I just forget how is it called) and display it accordingly...? – mirexS Jan 22 '23 at 21:26
  • There are endless examples of solving that here on Stack Overflow, see https://stackoverflow.com/a/7320527/252228, for instance. – Martin Honnen Jan 23 '23 at 08:09
  • @M.Honnen, yes it's true, but for some reason can't have saxon installed over my phone, so I have to stick to frameless processor. And with this one, up through your previous solution: http://xsltransform.net/bEzkntf this kind of expression: produces nothing at output. It correctly outputs the html table structure, but no actual useful data in it. That's why I actually made this second question attempt... Maybe some other solution or something.. – mirexS Jan 23 '23 at 10:24
  • @M.Honnen, as far as the other solutions you mentioned.. well, it's also very difficult here to express much of the stuff, as I'm very limited in the number of characters.. I'm not very accostomed with group by and sequences and also how pages should be actually controlled through js and all that stuff... Well.. that would be it for now.... Thanks on your time... – mirexS Jan 23 '23 at 10:28

0 Answers0