logo
down
shadow

Creating structured documents using nested XSLT2 grouping


Creating structured documents using nested XSLT2 grouping

By : Grozavu Alexandru
Date : November 19 2020, 12:41 AM
I hope this helps you . Either write a recursive function doing the grouping for each level or nest the for-each-group elements:
code :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    xmlns="http://www.w3.org/1999/xhtml"
    xpath-default-namespace="http://www.w3.org/1999/xhtml"
    version="2.0">

<xsl:output method="xhtml" indent="yes"/>

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="body">
  <xsl:copy>
    <xsl:for-each-group select="*" group-starting-with="h1">
      <div class="h1">
        <xsl:apply-templates select="."/>
        <xsl:for-each-group select="current-group() except ." group-starting-with="h2">
          <xsl:choose>
            <xsl:when test="self::h2">
              <div class="h2">
                <xsl:apply-templates select="current-group()"/>
              </div>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="current-group()"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each-group>
      </div>
    </xsl:for-each-group>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
<html xmlns="http://www.w3.org/1999/xhtml">

   <body>
      <div class="h1">
         <h1>h1.1</h1>
         <p>p1.1</p>
         <p>p1.2</p>
         <div class="h2">
            <h2>h2.1.1</h2>
            <p>p2.1.1</p>
            <p>p2.1.2</p>
         </div>
         <div class="h2">
            <h2>h2.2</h2>
            <p>p2.1.2a</p>
            <p>p2.1.2b</p>
         </div>
      </div>
      <div class="h1">
         <h1>h1.2</h1>
         <p>p1.2a</p>
         <p>p1.2b</p>
         <div class="h2">
            <h2>2.1</h2>
            <p>p2.2.1a</p>
            <p>p2.2.2b</p>
         </div>
      </div>
   </body>

</html>


Share : facebook icon twitter icon
XML transformation grouping using XSLT2

XML transformation grouping using XSLT2


By : meddy138
Date : March 29 2020, 07:55 AM
it helps some times Try using the below instead of   (which is missing a semi-colon by the way):
code :
<tr><td colspan="3"><br></br></td></tr>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="/">
  <html>
  <body>
  <h2>Some text</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Analysis</th>
    </tr>
    <xsl:for-each-group select="document/row" group-by="ILPROD">
    <xsl:for-each select="current-group()">
      <tr>
      <td><xsl:value-of select="WEEK"/></td>
      <td><xsl:value-of select="PERIOD"/></td>
      <td><xsl:value-of select="ILPROD"/></td>
    </tr>
    </xsl:for-each>
    <tr><td colspan="3"><br></br></td></tr>
    </xsl:for-each-group>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
<html>
    <body>
        <h2>Some text</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Analysis</th>
            </tr>
            <tr>
                <td>11</td>
                <td>201103</td>
                <td>some item</td>
            </tr>
            <tr>
                <td colspan="3"><br></td>
            </tr>
        </table>
    </body>
</html>
Grouping records in nested documents

Grouping records in nested documents


By : user2270207
Date : March 29 2020, 07:55 AM
it fixes the issue
Your problem here is basically with the way you currently have your document structured. The usage of "keys" under "vm" here that actually identify data points does not play well with the standard query forms and the aggregation framework in general.
code :
db.collection.find({
    "$or": [
        { "vm.0.type": "Block" },
        { "vm.1407484608965.type": "Block" }
        { ... }
    ]
})
{
    "_id" : ObjectId("533e6ab0ef2188940b00002c"),
    "uin" : "1396599472869",
    "vm" : [
        {
            "key": 0,
            "draw" : "01s",
            "count" : "2",
            "type" : "",
            "data" : {
                "title" : "K1"
            },
            "child" : [ 
                "1407484608965"
            ]
        },
        {
            "key": "1407484608965",
            "title" : "K2",
            "draw" : "1407473540857",
            "count" : "1",
            "type" : "Block",
            "child" : [ 
                "1407484647012"
            ]
        },
        {
            "key": "1407484647012",
            "title" : "K3",
            "draw" : "03.8878.98",
            "count" : "1",
            "type" : "SB",
            "child" : [ 
                "1407484762473"
            ]
        }
    ]
}
db.collection.find({ "vm.type": "Block" })
db.collection.aggregate([
    { "$match": { "vm.type": "Block" } },
    { "$unwind": "$vm" },
    { "$match": { "vm.type": "Block" } },
    { "$group": {
        "_id": "$_id",
        "uin": { "$first": "$uin" },
        "vm": { "$push": "$vm" }
    }}
])
db.collection.aggregate([
    { "$match": { "vm.type": "Block" } },
    { "$project": {
        "uin": 1,
        "vm": {
            "$setDifference": [
                { "$map": {
                    "input": "$vm",
                    "as": "el",
                    "in": {"$cond": [
                        { "$eq": [ "$$el.type", "Block" ] },
                        "$$el",
                        false
                    ]}
                }},
                [false]
            ]
        }
    }}
])
db.collection.find(function() {
    return Object.keys(this.vm).some(function(x) { 
        return this.vm[x].type == "Block" 
    })
})
MongoError: can't convert from BSON type missing to Date while Grouping records in nested documents

MongoError: can't convert from BSON type missing to Date while Grouping records in nested documents


By : BogSom
Date : March 29 2020, 07:55 AM
To fix the issue you can do Basically i want to group polls according to month. , Found solution after a long search:
code :
Poll.aggregate(

     // Un-wind the array's to access filtering 
     { $unwind: "$choices" },
     { $unwind: "$choices.votes" },
     { $unwind: "$choices.votes.votedOn" },

     // Group results to obtain the matched count per key
     { $group: {
         _id : { month: { $month: "$choices.votes.votedOn" }, year: { $year: "$choices.votes.votedOn" } },
         count: { "$sum": 1 }
     }}, function(er, d) {
        console.log(d)
     }
 )
[ 
    { _id: { month: 1, year: 2017 }, count: 3 },
    { _id: { month: 5, year: 2017 }, count: 3 } 
]
XSLT2.0: How to use nested for-each-group to compress xml records

XSLT2.0: How to use nested for-each-group to compress xml records


By : user2983001
Date : March 29 2020, 07:55 AM
I wish this help you I am trying to use nested for-each-group and for-each with current-group() to compress like data into one xml record based on two keys. The first key being ID and second being Inv_Link , Assuming your input sample is
code :
<Data>
    <Record>
        <ID>01_2019</ID>
        <Link>ICE2</Link>
        <Component_ID>DEBT</Component_ID>
        <Amt>1500</Amt>
    </Record>
    <Record>
        <ID>01_2019</ID>
        <Link>ICE1</Link>
        <Component_ID>EQT</Component_ID>
        <Amt>200</Amt>
    </Record>
    <Record>
        <ID>01_2019</ID>
        <Link>ICE1</Link>
        <Component_ID>CASH</Component_ID>
        <Amt>100</Amt>
    </Record>
    <Record>
        <ID>01_2020</ID>
        <Link>ICE3</Link>
        <Component_ID>CASH</Component_ID>
        <Amt>100</Amt>
    </Record>
</Data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:output indent="yes"/>

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="Data">
    <xsl:for-each-group select="Record" group-by="ID">
        <xsl:copy>
            <groupkey>
                <xsl:value-of select="current-grouping-key()"/>
            </groupkey>
            <AssetEvent>
                <xsl:copy-of select="ID"/>
                <DecompositionSequence>
                  <xsl:for-each-group select="current-group()" group-by="Link">
                      <groupkey>
                          <xsl:value-of select="current-grouping-key()"/>
                      </groupkey>
                      <Decompositions>
                          <InvestmentLink>
                              <xsl:value-of select="current-grouping-key()"/>
                          </InvestmentLink>
                          <DecompositionDataSequence>
                              <xsl:apply-templates select="current-group()"/>
                          </DecompositionDataSequence>
                      </Decompositions>
                  </xsl:for-each-group>
                </DecompositionSequence>
            </AssetEvent>

        </xsl:copy>
      </xsl:for-each-group>
    </xsl:template>

    <xsl:template match="Record">
        <DecompositionData>
            <xsl:apply-templates select="* except (ID, Link)"/>
        </DecompositionData>
    </xsl:template>

    <xsl:template match="Component_ID">
        <Component>
            <ID>
                <xsl:value-of select="."/>
            </ID>
        </Component>
    </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<Record>
   <groupkey>01_2019</groupkey>
   <AssetEvent>
      <ID>01_2019</ID>
      <DecompositionSequence>
         <groupkey>ICE2</groupkey>
         <Decompositions>
            <InvestmentLink>ICE2</InvestmentLink>
            <DecompositionDataSequence>
               <DecompositionData>
                  <Component>
                     <ID>DEBT</ID>
                  </Component>
                  <Amt>1500</Amt>
               </DecompositionData>
            </DecompositionDataSequence>
         </Decompositions>
         <groupkey>ICE1</groupkey>
         <Decompositions>
            <InvestmentLink>ICE1</InvestmentLink>
            <DecompositionDataSequence>
               <DecompositionData>
                  <Component>
                     <ID>EQT</ID>
                  </Component>
                  <Amt>200</Amt>
               </DecompositionData>
               <DecompositionData>
                  <Component>
                     <ID>CASH</ID>
                  </Component>
                  <Amt>100</Amt>
               </DecompositionData>
            </DecompositionDataSequence>
         </Decompositions>
      </DecompositionSequence>
   </AssetEvent>
</Record>
<Record>
   <groupkey>01_2020</groupkey>
   <AssetEvent>
      <ID>01_2020</ID>
      <DecompositionSequence>
         <groupkey>ICE3</groupkey>
         <Decompositions>
            <InvestmentLink>ICE3</InvestmentLink>
            <DecompositionDataSequence>
               <DecompositionData>
                  <Component>
                     <ID>CASH</ID>
                  </Component>
                  <Amt>100</Amt>
               </DecompositionData>
            </DecompositionDataSequence>
         </Decompositions>
      </DecompositionSequence>
   </AssetEvent>
</Record>
What would be better long term: Creating many documents in MongoDB or fewer documents with nested arrays

What would be better long term: Creating many documents in MongoDB or fewer documents with nested arrays


By : jashim
Date : March 29 2020, 07:55 AM
this will help Your question can be rephrased to one-to-many relationship with embedded documents VS one-to-many relationship with document references
There is no better or worst, it all depends on your use case. In your case for the long run, I think it's better off to go with one-to-many relationship with document references for these reasons I can think of:
Related Posts Related Posts :
  • Webpage doesn't scroll smoothly on screen
  • YouTube iframe, browser looks for file locally
  • html displaying inline image
  • Font acting differently on IE and Firefox
  • Encoding and decoding of the character references
  • An Image Button navigate to another site html/css
  • IE8 "Save Target as ..." won't display for block elements
  • Image hover transition for span - CSS
  • How to apply min and max on textarea?
  • How to draw multiple horizontal lines (Notebook Paper effect) using css?
  • Table Printing Issue: Gaps in top and Bottom Border of th Elements
  • grouping elements with div and applying stylesheet for that group
  • Click <div> to expand, then click again to shrink - Its expanding, just not shrinking
  • CSS - How can I center a <script>'s output?
  • Django's template variable gets interpreted as HTML
  • ngx datatable vertical scroll with rowheight set to auto
  • How to make input text border with CSS when it's OnFocus
  • Anyone know of a calendar web widget for my website I could use?
  • How does Bootstrap manage to use fixed positioning for navbar on iOS?
  • Centered text in fully clickable table cell
  • Compare HTML and HTML5
  • steps of creating webpage in bangla
  • css root element margin
  • What is the point of using absolute positioning in CSS?
  • Responsive solution for long URLs (that exceed the device width)
  • Divs don't collapse as they should - media queries
  • QTreeWidgetItem display html
  • Testing html/css image on local from jfiddle
  • long attribute value of HTML
  • Why my svg picture is truncated at the bottom when embedded in html
  • Display CSS: some divs fixed, some flexible (2)
  • How to append href strings with variables in html with PHP?
  • css - Why is there a big white space between text lines?
  • div image position fixed + scroll
  • Hide specific elements from html using css
  • how to align the arrow in menu item?
  • How do I create a trapezoidal button using CSS?
  • Background position seems to be inaccurate
  • CSS background color is overruled by the background image
  • Oblique or twisted border shape
  • Overflow in div tag doesn't work
  • How to show the vertical image into horizontal manner using HTML and CSS?
  • css3 animation issue move div to left and move it back
  • HTML <code> - get rid of newlines
  • Vertical Align Two Spans (Different font size)
  • Position fixed not working with video poster
  • Having issues placing html buttons side by side in a form
  • how to center text in the middle of the page
  • Sublime Autocompletion for HTML using Emmet inside .sublime-autocompletion file
  • Align bottom wrapped text at the left of an image
  • I'm trying to get :after:hover to work
  • Header and Picture won't Display Correctly
  • SVG stacking, anchor elements, and HTTP fetching
  • Positioning two elements on opposite ends of a 100% with header
  • How to overlay an image inside an image with HTML, CSS
  • Selected date isn't kept in select box
  • How to change background colour of entire div on hover?
  • Two gradients with two distinct sections with just one div element
  • Indent even rows of hexagons in CSS
  • Unwanted filled letters in webpage
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org