logo
down
shadow

XSLT 2.0 Grouping (for WordML) from XML


XSLT 2.0 Grouping (for WordML) from XML

By : Car Parts LV
Date : November 22 2020, 02:42 PM
it should still fix some issue I have a list of timecards to list as output in MS Word through WordML (using XSLT 2.0) and think I need to do some sort of grouping that I'm not certain how to complete (if at all possible). , I'd definitely use xsl:for-each-group...
code :
<xsl:for-each-group select="timecard"
  group-by="string-join((timekeeper/initials,date[@type='timecard']),'|')">
  <xsl:sort select="date[@type='timecard']"/>
  <w:p>
    <w:r>
      <w:t>
        <xsl:text>Date: </xsl:text>
        <xsl:value-of select="format-date(date, '[M01]/[D01]/[Y01]')"/>
      </w:t>
    </w:r>
  </w:p>
  <w:p>
    <w:r>
      <w:t>
        <xsl:text>Timekeeper: </xsl:text>
        <xsl:value-of select="timekeeper/initials"/>
      </w:t>
    </w:r>
  </w:p>
  <w:p>
    <w:r>
      <w:t>
        <xsl:text>Hours: </xsl:text>
        <xsl:value-of select="format-number(sum(current-group()/card-values/card-value[@type='billed']/hours), '###,##0.00')"/>
      </w:t>
    </w:r>
  </w:p>
  <w:p>
    <w:r>
      <w:t>
        <xsl:value-of select="current-group()/narrative/line" separator=" "/>
      </w:t>
    </w:r>
  </w:p>
  <w:p/>
</xsl:for-each-group>


Share : facebook icon twitter icon
How to create xpath for the wordml with styles - XSLT

How to create xpath for the wordml with styles - XSLT


By : Omar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Sample XML: , This XSLT will do the trick for you:
code :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.example.com"    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xs xd w my" version="2.0">
    <xsl:template match="text()"/>
    <xsl:template match="w:p">
        <p class="{my:getClass(.)}">
            <xsl:value-of select="normalize-space(.)"/>
        </p>
    </xsl:template>
    <xsl:variable name="styles" select="/*/w:styles" />
    <xsl:function name="my:getClass">
        <xsl:param name="curElem" />
        <xsl:variable name="curElemStyleName" select="$curElem//w:pStyle/@w:val"/>
        <xsl:variable name="curStyle" select="$styles//*[@w:styleId = $curElemStyleName]"/>
        <xsl:sequence select="$curStyle/w:name/@w:val"/>
    </xsl:function>
</xsl:stylesheet>
Using XSLT and WordML - new line character

Using XSLT and WordML - new line character


By : Jorge Diaz
Date : March 29 2020, 07:55 AM
To fix the issue you can do See XML - adding new line
This gives a complete answer to your question. What you do is based on what you need to do ... simply insert a w:br or adding new structure like adding multiple w:p elements.
XSLT grouping for wordml

XSLT grouping for wordml


By : sonu verma
Date : March 29 2020, 07:55 AM
With these it helps I would ignore the existing w:p elements altogether here. Ultimately what you want is a root element named root containing one w:p element for each run of adjacent w:r elements in the original source, regardless of whether or not those w:r elements were previously wrapped in a w:p. You can approach this using a technique I call sibling recursion - start with a template that fires for the first w:r in each group and then have it recurse to its immediately following sibling until you hit one that isn't another w:r.
code :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:w="http://foo.com">

  <xsl:template match="/">
    <root>
      <xsl:apply-templates mode="group"
          select=".//w:r[not(preceding-sibling::*[1][self::w:r])]" />
    </root>
  </xsl:template>

  <xsl:template match="w:r" mode="group">
    <w:p>
      <xsl:apply-templates select="." /><!-- applies non-"group" templates -->
    </w:p>
  </xsl:template>

  <xsl:template match="w:r">
    <xsl:copy-of select="."/>
    <xsl:apply-templates select="following-sibling::*[1][self::w:r]" />
  </xsl:template>
</xsl:stylesheet>
.//w:r[not(preceding-sibling::*[1][self::w:r])]
following-sibling::*[1][self::w:r]
XSLT 2.0 - High Level Grouping with Sums (WordML)

XSLT 2.0 - High Level Grouping with Sums (WordML)


By : CHENGLIANG YE
Date : March 29 2020, 07:55 AM
To fix the issue you can do The main thing you need to do is change the xsl:for-each-group to this...
code :
<xsl:for-each-group select="//invoice/matter/timecard-summary-by-timekeeper/timekeeper-summary/timekeeper" group-by="../@timekeeper-id">
<w:t>
  Hours: 
 <xsl:value-of select="format-number(sum(current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total[@type='hours']), '###,##0.00')" />
 for $
 <xsl:value-of select="format-number(sum(current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total[@type='amount']), '###,##0.00')" />
</w:t>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
               xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
                version="2.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <xsl:call-template name="XJ_TKSummary_02" />
    </xsl:template>

    <xsl:template name="XJ_TKSummary_02">
       <xsl:variable name="TW" select="1440" />
        <xsl:for-each-group select="//invoice/matter/timecard-summary-by-timekeeper/timekeeper-summary/timekeeper" group-by="../@timekeeper-id">
            <w:p>
                <w:r>
                    <w:t><xsl:value-of select="initials" /> - <xsl:value-of select="billingname" /></w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <xsl:variable name="groupTotals" select="current-group()/timekeeper-summary-totals/timekeeper-summary-total[@type='billed']/total" />
                    <w:t>
                        Hours: <xsl:value-of select="format-number(sum($groupTotals[@type='hours']), '###,##0.00')" />
                        for $ <xsl:value-of select="format-number(sum($groupTotals[@type='amount']), '###,##0.00')" />
                    </w:t>
                </w:r>
            </w:p>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>
XML to WordML using XSLT 1.0 - replace html tags within xml content with wordML formatting tags

XML to WordML using XSLT 1.0 - replace html tags within xml content with wordML formatting tags


By : user3740958
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Working with WordML is tricky. One tip when converting arbitrary XML to WordML using XSLT is to not worry about the text runs when processing blocks, but to instead create a template that matches text() nodes directly, and create the text runs there. It turns out that Word doesn't care if you nest text runs, which makes the problem much easier to solve.
Related Posts Related Posts :
  • htmlToText not found
  • Excel XML import creates extra column called NULL for null values
  • Compare value of two nodes of same type using xslt
  • XPath - Selecting xml nodes with attributes with names that follow pattern
  • Special Characters will not be removed from XML via XLST
  • WSO2 Identity XACML - Support for Condition Statement?
  • How to combine multiple XML Files with XQuery
  • XSLT select all text and specific node
  • how to interpret the jacoco.xml file?
  • XSLT with different closing tags
  • How to remove an element in Groovy using XmlSlurper?
  • Each result on a new line XQuery
  • Understanding multi-level XML reference using Perl XML Parser?
  • XQuery function to limit the number of records in the output
  • How to write an XQuery flwor expression to calculate the probability between words?
  • XSL translator which removes blank space and convert inches to feet
  • Parse JUnit result XML format (created by 3rd party tool) with Maven
  • Invalid content was found starting with element 'sport'. One of '{spalanie}' is expected
  • How to select particular node from XML
  • FLWOR XQuery to return only unique words combinition, and the number of times the combinition occured, sorted in descend
  • How can I get Chrome to display XML styled with XSL?
  • XML Schema: keyref with optional field
  • Validate and revise XML: schema or code?
  • How to append a node in an XML file with node.js fast without string comparison
  • Searching XML using XPath returning no nodes
  • How to add attribute for child node in XSL?
  • Golang xml doesn't unmarshal
  • Turn XML attribute with 2 or more values into SVG x/y coordinates using XSL
  • Connect to a complex SOAP Web Service
  • solr 5.3.1 verifying that schema.xml is loaded
  • updated xml through excel 2010 vba and calling command for use in windows command line
  • Convert xml date output yyyy-mm-ddThh:mm:ss to dd-mmm-yy using xsl1.0
  • Template returns true() when is told to return false
  • XML node cannot traced
  • is there a difference between <element/> and <element></element> in XML?
  • Extracting attribute value from non context element
  • Can xsd type of 'anyURI' contain spaces?
  • Wiktionary in Structured Format
  • Passing a parameter in XMLA
  • How to add a single element to the end of an xml using xslt?
  • cannot found web.xml error while restarting app in openshift
  • XML Recursive Adding beyond parent node
  • XSLT Identity Transformation while removing all attributes
  • How to reference grouped elements in XSLT 2.0?
  • Unix - Format XML to single line nodes
  • Surround XML elements with CDATA section via XSLT
  • Covert an XML which contains &lt; &gt; in it, using XSLT
  • Using XML prefixes/namespaces to create an Xpath
  • Is there a way to infer an ontology from an XML data file
  • How to restrict the value of an XML element using xsi:type in XSD?
  • Invalid content was found starting with element 'beans:http'
  • Get all nodes as new Elements without tree structure
  • xslt assign a path to a variable and call the variable later on
  • Wrap XML response with JAXB and Jersey
  • How to open an excel file in R where file format and file extension differ?
  • Can we define an xsd with same named element with different attributes, Will this be a valid xsd?
  • Analyze text() node and add new nodes in XSLT
  • VB.NET Query Linq for get all elements node
  • XML: Webservice returns multiple root elements
  • Using XPath to extract elements from a specific location in the document
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co