0

I'm in very need for the following request. I do have some persons .xml file through which I suppose displaying some persons along through their relatives (spouse, child, children etc). So things goes like this (persons.xml)

<persons>
 <person> 
  <frst_name>Boris</frst_name> <!-- first name -->
  <surname>David</surname>      <!-- last name -->
  <gender>M</gender>
  <age>38</age>
  <address>2nd Catherine st, mtl</address>
  <reltives>
   <relation>
    <frst_name>Karen</frst_name>
    <surname>David</surname>
    <gender>F</gender>
    <age>31</age>
   <reltion_type>married</reltion_type> <!-- spouse -->
  </relation>
 </reltives>
</person>
<person> 
 <frst_name>Lucy</frst_name>    
 <surname>Scott</surname>         
 <gender>F</gender>
 <age>41</age>
 <address>5th summer st, mntb</address>
 <reltives>
  <relation>
  <frst_name>Paul</frst_name>
  <surname>Scott</surname>
  <gender>M</gender>
  <age>48</age>
  <reltion_type>married</reltion_type> 
 </relation> 
  <relation>
  <frst_name>Emma</frst_name>
  <surname>Scott</surname>
  <gender>F</gender>
  <age>12</age>
 <reltion_type>child</reltion_type> <!-- daughter -->
</relation>
</reltives>
</person>
<person> 
 <frst_name>Thomas</frst_name>
 <surname>Anderson</surname>
 <gender>M</gender>
 <age>34</age>
 <address>19th Penfield ave, brtcl</address>
 <reltives>
  <relation>
  <frst_name>Michael</frst_name>
  <surname>Anderson</surname>
  <gender>M</gender>
  <age>5</age>
  <reltion_type>child</reltion_type> <!-- son -->
  </relation> 
<relation>
 <frst_name>Aubrey</frst_name>
 <surname>Anderson</surname>
 <gender>F</gender>
 <age>7</age>
 <reltion_type>child</reltion_type> <!-- daughter -->
 </relation>
</reltives>
</person>
</persons>  

Through that file check one could notice that through node there are a couple of text child nodes: , , as well as other child node which is different from the ones mentioned, as it contains other child node , which, in turn, contains other bunch of text child nodes as well. My main request is for contracted tabular displaying of all those principal detail lines about person(s). It's basically one line resembling one sql table record from some table. So my poor .xsl stylesheet file is:

<?xml version="1.0" encoding="UTF-8"?>
   <xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html"/> 
  <xsl:template match="/"> 
  <html>
   <head>
   <meta name="viewport" content="width=device-width, user-scalable=no"></meta> <!-- content="initial-scale=1" -->
    <xsl:element name="script">
     <xsl:attribute name="src">https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js</xsl:attribute>
     </xsl:element>
  <xsl:element name="script">
   <xsl:attribute name="src">https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js</xsl:attribute>
  </xsl:element>   
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"></link>
 </head>
 <body>
  <h4>People (and relatives) listing</h4>
  <div class="container">
   <table id="PrsnsTbl" class="table" border="1">
   <tr><th>First Name</th> <th>Last Name</th> <th>Gender</th><th>Age</th> 
     <th>Address</th></tr>
    <xsl:for-each select="persons/person">
    <tr data-target="#lin-rel" data-toggle="collapse" class="accordion-toggle">
    <xsl:for-each select="child::*/child::text()[not(following-sibling::*)]">
     <td> <xsl:value-of select="."/> </td>
   </xsl:for-each>  
  </tr>
   <div id="lin-rel" class ="accordion-body collapse"> 
   <tr> <th>val1</th> <th>val2</th> <th>val3</th></tr>
    <xsl:for-each select="person/reltives/relation">
     <tr class="hiddenRow">   
       <xsl:for-each select="child::*/child::text()">
         <td> <xsl:value-of select="."/> </td>
       </xsl:for-each>
      </tr>
     </xsl:for-each>
     </div> 
     </xsl:for-each> 
     </table>
    </div> <!-- end container -->
    </body>
   </html>
  </xsl:template>
  </xsl:stylesheet>

I mean, first time that display is showed up, all principal lines they'll appear contracted. And as one'll notice, there'll be a plus sign through that far left corner (it's not yet through the .xsl code, but I want it put there). So when it'll be clicked (that "+" sign), that initial contracted line it'll be get expanded in order to show the other ,,hidden" information pertaining that particular person. For example, I'll show up in here some example for one principal line, same logic following the rest of the other remaining principal lines.

    First Name   Last Name  Gender  Age           Address
 +    Boris       David       M     38     2nd Catherine st, mtl

and if one clicks over that "+" sign, this display will turn into this one:

   First Name   Last Name  Gender  Age           Address
 -    Boris       David       M     38    2nd Catherine st, mtl
                  frst nme   srnme  gndr  age rltn_type
                   Karen     David   F    31   married

This is that sort of 1-to-1 or 1-to-n relationship displaying, pretty much like an accordion behaviour. I already asked this (similar) question - well with some variation - (through this stkovrflw:

1 to n relationship between xml principal records and other bunch of related node values (III) )

but it aint't been replied whatsoever. I'll also show a couple of links where I detailed exactly how this I'd like to be accomplished First it's a fiidle link:

https://jsfiddle.net/MrcaS48/6Ljv0xoh/164

and the second it's also some response from somewhat similar question which have been asked also here over stakoverflow:

Cannot navigate through an XML using XSLT

The whole point here is that I'm just trying to do all these with the bootstrap help for hiding and unhiding lines as I just noticed been done throgh that stkoverflow example. That's why through my xsl stylesheets I simply add up some bootstrap references. But, still I don't know how to use them right.

                              *

So, basically my first requirement - regarding this matter - is for displaying through that two for-each loops only those text child nodes of that person node (which I just don't know how to do it) and no reltives node. In other words, through that two for-each loops I want to display only these child text nodes: and NOT node as this is that hidden part which will eventually gets expanded ONLY through the click of that "+" sign. As one'll notice the only closest xpath construction I was able to come up with, was this one:

select="child::*/child::text()[not(following-sibling::*)]"

but that one is still displaying another additional cell over each principal table line. Ain't got no clue how to "cleanly" display it without that additional cell ! This would be basically my first requirement, as the second one for expanding/contracting I think is have pretty much to do with bootstrap. If someone will be kind enough in helping me solve this out also I'd appreciate it a great deal. Perhaps it's a little bit tangled all the stuff i require, but please, you guys help me with this, as I'm in very much need for this to be done !!

Thank you guys very much in advance !!

mcaS48
  • 33
  • 8

1 Answers1

0

Answer to the first question is as follows:

  • one should change that expression so it reads:

    select="child::*[not(child::*/text())]"
    

This way the stylesheet will only display those principal lines without all that containment node (along with all the other children nodes in it) !

mcaS48
  • 33
  • 8