I have tried for hours to multiply 2 varibales in XSLT1 but I can't seem to figure it out.
The result shows in excel as NaN
I have searched for a while but I'm having trouble with this, just started using XSLT
Variables:
Weight = 10
Length = 12
XSLT:
<xsl:variable name ="content"><xsl:value-of select="$length * $weight" /></xsl:variable>
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rvmon="rosenbergverft.com:3D/2017/WeightMTO" xmlns:pdms="rosenbergverft.com:3D/2010/Models">
<xsl:output method="text" omit-xml-declaration="yes" standalone="no" media-type="text/xls" />
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="." />
<xsl:template match="/">Building block;Discipline;Area;Sub. Area;Syst. no.;Weight Item no.;Piecemark no.;Weight Item Descr.;CompType;Type code;Rating or Scedule;Spec.;Dim. (");Material;Cost Code COR;Weight Phase Code;Mod. Phase Code;Weight Status % (allow.);Mod. Constr. Code;Mod. Handl. Code;No. off;Unit Length/ Area (m,m2, m3);Unit Weight (kg/m, m2, m3);Unit Weight MON(kg/m, m2, m3);Net Dry Weight (kg);Gross Dry Weight (kg);Content Weight (kg);Installed weight;CoG East;CoG North;CoG Elevation;Ref. doc., dwg., P&ID etc.;Remarks;Cost for instrument valves [NOK];install code;MON Lift Code;Paint Surface;Insulation Class;
<xsl:for-each select="/rvmon:WeightMTO/rvmon:MTOOwner"><xsl:for-each select="rvmon:Piecemark/rvmon:WeightItemNo/rvmon:Part">
<xsl:variable name= "weight" select="format-number(rvmon:ContentWeight/#number, '#0,0##', 'euro')" />
<xsl:variable name="length"><xsl:choose><xsl:when test="contains(rvmon:CompType,'BOLT')"><xsl:text> 1 </xsl:text></xsl:when><xsl:when test="rvmon:UnitLength/#unit = 'mm'"><xsl:value-of select="format-number(rvmon:UnitLength/#number div 1000, '#0,0##', 'euro')" /></xsl:when><xsl:when test="rvmon:UnitLength/#unit = 'mm2'"><xsl:value-of select="format-number(rvmon:UnitLength/#number div 1000000, '#0,0##', 'euro')" /></xsl:when><xsl:when test="rvmon:UnitLength/#unit = 'mm3'"><xsl:value-of select="format-number(rvmon:UnitLength/#number div 1000000000, '#0,0##', 'euro')" /></xsl:when><xsl:otherwise><xsl:value-of select="format-number(rvmon:UnitLength/#number, '#0,0##', 'euro')" /></xsl:otherwise></xsl:choose></xsl:variable>
<xsl:variable name="content" select="$length * $weight" />
<xsl:value-of select="../../../rvmon:BuildingBlock" />;<xsl:value-of select="rvmon:Discipline" />;<xsl:value-of select="../../../rvmon:Module" />;<xsl:value-of select="../../../rvmon:SubArea" />;<xsl:value-of select="../../../rvmon:SystNo" />;<xsl:value-of select="rvmon:WeightItemNo" />;<xsl:value-of select="rvmon:Piecemark" />;<xsl:value-of select="rvmon:WeightItemDescr" />;<xsl:value-of select="rvmon:CompType" />;<xsl:value-of select="rvmon:TypeCode" />;<xsl:value-of select="rvmon:Rating" />;<xsl:value-of select="rvmon:Spec" />;<xsl:choose><xsl:when test="rvmon:Discipline = 'L'"><xsl:value-of select="format-number(rvmon:Dim/#number, '#0,##', 'euro')" /><xsl:choose><xsl:when test="rvmon:Dim/#unit = 'inch'">"</xsl:when><xsl:otherwise><xsl:value-of select="rvmon:Dim/#unit" /></xsl:otherwise></xsl:choose></xsl:when><xsl:when test="rvmon:Discipline = 'N'"></xsl:when><xsl:otherwise><xsl:value-of select="format-number(rvmon:Dim/#number, '#0,##', 'euro')" /><xsl:value-of select="rvmon:Dim/#unit" /></xsl:otherwise></xsl:choose>;<xsl:value-of select="rvmon:Material" />;<xsl:value-of select="rvmon:CostCodeCOR" />;<xsl:value-of select="rvmon:WeightPhaseCode" />;<xsl:value-of select="rvmon:ModPhaseCode" />;<xsl:value-of select="format-number(rvmon:WeightStatus/#number * 100, '00', 'euro')" />%;<xsl:value-of select="rvmon:ModConstrCode" />;<xsl:value-of select="rvmon:ModHandlCode" />;<xsl:value-of select="format-number(rvmon:NoOff/#number, '#0,###', 'euro')" />;<xsl:value-of select="$length"/>;<xsl:if test="rvmon:ModHandlCode = 'RP'">-</xsl:if><xsl:value-of select="format-number(rvmon:UnitWeight/#number, '#0,0##', 'euro')" />;<xsl:if test="rvmon:ModHandlCode = 'RP'">-</xsl:if><xsl:value-of select="format-number(rvmon:MONUnitWeightFactor/#number, '#0,0#####', 'euro')" />;<xsl:choose><xsl:when test="contains(rvmon:CompType,'BOLT')"><xsl:text> 1 </xsl:text></xsl:when><xsl:otherwise><xsl:value-of select="format-number(rvmon:NetDryWeight/#number, '#0,0##', 'euro')" /></xsl:otherwise></xsl:choose>;<xsl:value-of select="format-number(rvmon:AllowanceWeight/#number, '#0,0##', 'euro')" />;<xsl:if test="rvmon:ModHandlCode = 'RP'">-</xsl:if><xsl:value-of select="$weight"/>;<xsl:if test="rvmon:ProdStatus ='ABC' "><xsl:text> Yes </xsl:text></xsl:if>;<xsl:value-of select="format-number(rvmon:CoGEast/#number div 1000, '#0,0##', 'euro')" />;<xsl:value-of select="format-number(rvmon:CoGNorth/#number div 1000, '#0,0##', 'euro')" />;<xsl:value-of select="format-number(rvmon:CoGElevation/#number div 1000, '#0,0##', 'euro')" />;<xsl:value-of select="../../../rvmon:DrawNumber" />;<!-- xsl:value-of select="rvmon:Remarks" / --><xsl:value-of select="../../../pdms:PDMSElement/pdms:ElementName/#text" />;;;;<xsl:value-of select="format-number(rvmon:PaintSurface/#number div 1000000, '#0,0##', 'euro')" />;<xsl:value-of select="../../../rvmon:InsulationClass" />;<xsl:value-of select="$length"/>;<xsl:value-of select="$content"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XML-document
<UnitLength number="1.000" unit="pcs" field="Quantity" />
<ContentWeight number="8.005" unit="kg" field="ContentWeight" /> />
I am able to output "weight" and "length" by itself. But I cant even do
"weight * 10"
Sorry if it is messy.
You need to remove all formatting number while assigning the variable and while multipled result need to format number like below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rvmon="rosenbergverft.com:3D/2017/WeightMTO"
exclude-result-prefixes="#all"
version="1.0">
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="." />
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:variable name= "weight" select="//rvmon:ContentWeight/#number" />
<xsl:variable name="length">
<xsl:choose>
<xsl:when test="contains(//rvmon:CompType,'BOLT')">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="rvmon:UnitLength/#unit = 'mm'">
<xsl:value-of select="//rvmon:UnitLength/#number div 1000" />
</xsl:when>
<xsl:when test="rvmon:UnitLength/#unit = 'mm2'">
<xsl:value-of select="//rvmon:UnitLength/#number div 1000000" />
</xsl:when>
<xsl:when test="rvmon:UnitLength/#unit = 'mm3'">
<xsl:value-of select="//rvmon:UnitLength/#number div 1000000000" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//rvmon:UnitLength/#number" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="content" select="format-number(($weight * $length), '#0,0##', 'euro')" />
<xsl:value-of select="$content"/>
</xsl:template>
</xsl:stylesheet>
You have:
<xsl:variable name= "weight" select="format-number(rvmon:ContentWeight/#number, '#0,0##', 'euro')" />
A number formatted to use a decimal comma is no longer a number for the purposes of XPath/XSLT. A number can contain only digits and a decimal period.
Assuming that the original values (not shown in your question) are true numbers, use them for the multiplication, and format them only for the output.
Related
I have the target /aggregate-rating.xml
<aggregate>
<rating>
<issuerNumber>388d</issuerNumber>
<WAABCA>baa1</WAABCA>
<WAABCANumeric>14.2</WAABCANumeric>
<WANotches>3.4</WANotches>
<WALTRatingNumeric>17.6</WALTRatingNumeric>
</rating>
<rating>
<issuerNumber>89f8</issuerNumber>
<WAABCA>b2</WAABCA>
<WAABCANumeric>7.4</WAABCANumeric>
<WANotches>-1.6</WANotches>
<WALTRatingNumeric>5.8</WALTRatingNumeric>
</rating>
===================================
</aggregate>
Mapping /rating-chart.xml
<ratings>
<rating MD="Aaa" SP="AAA" Grade="Investment" rank="1"/>
==================================
<rating MD="A1" SP="A+" Grade="Investment" rank="5"/>
<rating MD="A2" SP="A" Grade="Investment" rank="6"/>
<rating MD="A3" SP="A-" Grade="Investment" rank="7"/>
<rating MD="Baa1" SP="BBB+" Grade="Investment" rank="8"/>
========================
<rating MD="B2" SP="B" Grade="Non-Investment" rank="15"/>
<rating MD="B3" SP="B-" Grade="Non-Investment" rank="16"/>
<rating MD="Caa1" SP="CCC" Grade="Non-Investment" rank="17"/>
====================================
<rating MD="C" Grade="Non-Investment" rank="21"/>
</ratings>
The scale is based on WANotches. e.g issuer 388d, its WAABCA is baa1 (rank 8) then it notches 3.4 (round to 3), its rank is boosted to 5. The adjusted rating will be <rating MD="A1" SP="A+" Grade="Investment" rank="5"/>
Expected result:
<aggregate>
<rating>
<issuerNumber>388d</issuerNumber>
<WAABCA>baa1</WAABCA>
<WAABCANumeric>14.2</WAABCANumeric>
<WANotches>3.4</WANotches>
<WALTRatingNumeric>17.6</WALTRatingNumeric>
<adjustedMoody>A1</adjustedMoody>
<adjustedStandardPoor>A+</adjustedStandardPoor>
<adjustedGrade>Investment</adjustedGrade>
</rating>
<rating>
<issuerNumber>89f8</issuerNumber>
<WAABCA>b2</WAABCA>
<WAABCANumeric>7.4</WAABCANumeric>
<WANotches>-1.6</WANotches>
<WALTRatingNumeric>5.8</WALTRatingNumeric>
<adjustedMoody>Caa1</adjustedMoody>
<adjustedStandardPoor>CCC</adjustedStandardPoor>
<adjustedGrade>Non-Investment</adjustedGrade>
</rating>
=======================================
</aggregate>
My xsl:
<xsl:variable name="ratingChart" select="doc('/rating-chart.xml')"/>
<xsl:template match="rating">
<xsl:variable name="notch" select="round(WANotches)"/>
<xsl:variable name="currentRank" select="$ratingChart/ratings/rating[upper-case(#MD) eq upper-case(WAABCA)]/#rank"/>
<xsl:variable name="notchRank" select="$currentRank - $notch"/>
<xsl:variable name="aggRank" select="$ratingChart/ratings/rating[#rank = $notchRank]"/>
<xsl:variable name="adjustedMD" select="$aggRank/#MD"/>
<xsl:variable name="adjustedSP" select="$aggRank/#SP"/>
<xsl:variable name="adjustedGrade" select="$aggRank/#Grade"/>
<xsl:copy>
<xsl:sequence select="$aggRank"/>
<xsl:apply-templates/>
<xsl:call-template name="aggrRating">
<xsl:with-param name="aMD" select="$adjustedMD"/>
<xsl:with-param name="aSP" select="$adjustedSP"/>
<xsl:with-param name="aGrade" select="$adjustedGrade"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="aggrRating">
<xsl:param name="aMD"/>
<xsl:param name="aSP"/>
<xsl:param name="aGrade"/>
<adjustedMoody><xsl:value-of select="$aMD"/></adjustedMoody>
<adjustedStandardPoor><xsl:value-of select="$aSP"/></adjustedStandardPoor>
<adjustedGrade><xsl:value-of select="$aGrade"/></adjustedGrade>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
I got all the blank elements : <adjustedMoody>, <adjustedStandardPoor>, <adjustedGrade>.
How can I fix my xsl?
A list of numbers corresponding to the factors is defined with this string : 24850973612485097361
The number is flipped and is multiplied for each number with the factor corresponding to its position, 0 corresponding to 10 and all cumulated
For example, for and order having the number 28200703:
The number is flipped giving 30700282
Using the factor string 24850973612485097361 for the corresponding size for the number, the calculation is done as following:
3 x 2 = 6
0 x 4 = 0
7 x 8 = 56
0 x 5 = 0
0 x 10 = 0
2 x 9 = 18
8 x 7 = 56
2 x 3 = 6
Cumulated: 142
Try it this way:
<xsl:template name="process">
<xsl:param name="number"/>
<xsl:param name="factors" select="'24850973612485097361'"/>
<xsl:param name="accumulated" select="0"/>
<xsl:choose>
<xsl:when test="$number">
<xsl:variable name="n" select="$number mod 10" />
<xsl:variable name="m" select="substring($factors, 1, 1)" />
<xsl:call-template name="process">
<xsl:with-param name="number" select="floor($number div 10)"/>
<xsl:with-param name="factors" select="substring($factors, 2)"/>
<xsl:with-param name="accumulated" select="$accumulated + $n * $m" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$accumulated"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Example of call:
<xsl:call-template name="process">
<xsl:with-param name="number" select="28200703"/>
</xsl:call-template>
Demo: http://xsltransform.net/3MvmrAF
I want to set the page size that should be dynamic according to the page contents.
That is, I want the page size of the PDF should be just as per the content size and not like A4, letter or something else.
My code is:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns="http://www.w3.org/1998/Math/MathML">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body" font="12pt Times">
<fo:block font-size="1.5em" font-weight="bold" role="html:p">
<fo:instream-foreign-object>
<math display="inline">
<mrow>
<mi>A</mi>
<mo>=</mo>
<mi>Ï€</mi>
<msup>
<mi>r</mi>
<mn>2</mn>
</msup>
</mrow>
</math>
</fo:instream-foreign-object>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
What I get is:
What I need is:
You could probably accomplish what you wish by changing the process slightly. JEuclid has an "foprep" function that would convert the MathML inside of XSL FO into the inline SVG for you. You could then apply an identity-translate on the resulting XSL FO to use the dimensions of the SVG as the dimensions of the page.
I did not do a complete test, but foprep on your sample would yield something like this (note I changed a few things like removing any margin on the original page and also set line-height on the block to "0" so that an exact size image fits.
This is what is the result of running "foprep" on your document.
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns="http://www.w3.org/1998/Math/MathML">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body" font="12pt Times">
<fo:block line-height="0">
<fo:instream-foreign-object alignment-adjust="-9.090909%">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" color-interpolation="auto"
color-rendering="auto" contentScriptType="text/ecmascript"
contentStyleType="text/css" fill="black" fill-opacity="1"
font-family="'Dialog'" font-size="12" font-style="normal"
font-weight="normal" height="11" image-rendering="auto"
preserveAspectRatio="xMidYMid meet" shape-rendering="auto" stroke="black"
stroke-dasharray="none" stroke-dashoffset="0" stroke-linecap="square"
stroke-linejoin="miter" stroke-miterlimit="10" stroke-opacity="1"
stroke-width="1" text-rendering="auto" version="1.0" width="39"
zoomAndPan="magnify">
<!--Converted from MathML using JEuclid-->
<defs id="genericDefs"/>
<g>
<g color-interpolation="linearRGB" color-rendering="optimizeQuality"
image-rendering="optimizeQuality"
text-rendering="optimizeLegibility" transform="translate(0.5469,10)">
<path
d="M3.9688 0 L4.0312 -0.2812 Q4.2969 -0.3125 4.4453 -0.4375 Q4.5938 -0.5625 4.6562 -0.7969 Q4.7188 -1.0312 4.7188 -1.4062 Q4.7188 -1.625 4.7031 -1.9062 L4.6719 -2.6562 L2.0938 -2.6562 L1.7656 -2.0781 Q1.5312 -1.6719 1.4297 -1.3828 Q1.3281 -1.0938 1.3281 -0.875 Q1.3281 -0.375 1.9219 -0.2812 L1.8594 0 L-0.5469 0 L-0.4844 -0.2812 Q-0.2969 -0.3125 -0.1328 -0.4297 Q0.0312 -0.5469 0.2109 -0.7891 Q0.3906 -1.0312 0.7188 -1.5938 L4.4688 -8.0938 L5.3594 -8.0938 L5.7812 -1.5625 Q5.8125 -1.0938 5.8828 -0.8359 Q5.9531 -0.5781 6.0859 -0.4531 Q6.2188 -0.3281 6.4688 -0.2812 L6.4062 0 L3.9688 0 ZM2.3438 -3.1719 L4.6406 -3.1719 L4.5469 -5.0469 Q4.5312 -5.4375 4.5156 -6.0156 Q4.5 -6.5938 4.5 -6.8594 L4.4375 -6.8594 L2.3438 -3.1719 Z"
stroke="none"/>
</g>
<g color-interpolation="linearRGB" color-rendering="optimizeQuality"
image-rendering="optimizeQuality"
text-rendering="optimizeLegibility" transform="translate(9.0775,10)">
<path
d="M0.7344 -4.2344 L0.7344 -5.0469 L5.9219 -5.0469 L5.9219 -4.2344 L0.7344 -4.2344 ZM0.7344 -1.8125 L0.7344 -2.625 L5.9219 -2.625 L5.9219 -1.8125 L0.7344 -1.8125 Z"
stroke="none"/>
</g>
<g color-interpolation="linearRGB" color-rendering="optimizeQuality"
image-rendering="optimizeQuality"
text-rendering="optimizeLegibility"
transform="translate(17.7957,10)">
<path
d="M2.5 -1.4688 Q2.5 -1.0781 2.5234 -0.8906 Q2.5469 -0.7031 2.6094 -0.6016 Q2.6719 -0.5 2.7891 -0.4297 Q2.9062 -0.3594 3.1875 -0.2812 L3.1875 0 L0.7031 0 L0.7031 -0.2812 Q1.0781 -0.375 1.1953 -0.4922 Q1.3125 -0.6094 1.3516 -0.8203 Q1.3906 -1.0312 1.3906 -1.4688 L1.3906 -6.5312 Q1.3906 -6.9375 1.3672 -7.125 Q1.3438 -7.3125 1.2734 -7.4141 Q1.2031 -7.5156 1.0938 -7.5781 Q0.9844 -7.6406 0.7031 -7.7188 L0.7031 -8 L3.1875 -8 L3.1875 -7.7188 Q2.9219 -7.6406 2.8125 -7.5781 Q2.7031 -7.5156 2.6328 -7.4219 Q2.5625 -7.3281 2.5312 -7.1328 Q2.5 -6.9375 2.5 -6.5312 L2.5 -1.4688 ZM3.5176 -9.9062 L3.5176 -8.875 L2.5332 -8.875 L2.5332 -9.9062 L3.5176 -9.9062 ZM1.3457 -9.9062 L1.3457 -8.875 L0.377 -8.875 L0.377 -9.9062 L1.3457 -9.9062 ZM6.7344 -3.0781 Q6.7812 -2.5 6.9141 -2.0156 Q7.0469 -1.5312 7.2812 -1.1797 Q7.5156 -0.8281 7.8438 -0.625 Q8.1719 -0.4219 8.625 -0.4219 Q9.1094 -0.4219 9.4141 -0.5234 Q9.7188 -0.625 9.9219 -0.8516 Q10.125 -1.0781 10.3125 -1.5312 L10.8906 -1.5312 L10.8906 -0.2031 Q10.3594 -0.0625 9.7891 0.0156 Q9.2188 0.0938 8.5312 0.0938 Q7.2188 0.0938 6.4844 -0.7109 Q5.75 -1.5156 5.5938 -3.0781 L4.2031 -3.0781 L4.2031 -3.6406 L5.5625 -3.6406 L5.5625 -3.9375 Q5.5625 -4.2969 5.5938 -4.6719 L4.625 -4.6719 L4.625 -5.2344 L5.6875 -5.2344 Q5.9688 -6.6094 6.8125 -7.3516 Q7.6562 -8.0938 8.9062 -8.0938 Q9.4375 -8.0938 9.8828 -8.0391 Q10.3281 -7.9844 10.8906 -7.8281 L10.8906 -6.5 L10.3125 -6.5 Q10.1719 -6.9062 9.9531 -7.1406 Q9.7344 -7.375 9.4531 -7.4766 Q9.1719 -7.5781 8.7656 -7.5781 Q8.2812 -7.5781 7.8672 -7.3047 Q7.4531 -7.0312 7.1719 -6.5078 Q6.8906 -5.9844 6.7812 -5.2344 L10.3281 -5.2344 L10.3281 -4.6719 L6.7344 -4.6719 Q6.7031 -4.4062 6.7031 -4.0156 L6.7031 -3.8438 Q6.7031 -3.7344 6.7031 -3.6406 L9.9219 -3.6406 L9.9219 -3.0781 L6.7344 -3.0781 Z"
stroke="none"/>
</g>
<g color-interpolation="linearRGB" color-rendering="optimizeQuality"
image-rendering="optimizeQuality"
text-rendering="optimizeLegibility"
transform="translate(28.6863,10)">
<path
d="M2.3281 -5.6562 L2.6875 -5.6562 L2.2812 -4.2188 L2.3438 -4.1875 Q2.9062 -4.9531 3.4375 -5.3281 Q3.9688 -5.7031 4.5312 -5.7031 Q4.9531 -5.7031 5.2344 -5.625 L4.9531 -4.3125 L4.3594 -4.3125 Q4.3125 -4.625 4.2109 -4.7812 Q4.1094 -4.9375 3.8906 -4.9375 Q3.6719 -4.9375 3.375 -4.7031 Q3.0781 -4.4688 2.7656 -4.0625 Q2.4531 -3.6562 2.2969 -3.3047 Q2.1406 -2.9531 2.0625 -2.5312 L1.5312 0 L0.5156 0 L1.4062 -4 Q1.5312 -4.5469 1.5312 -4.8438 Q1.5312 -5 1.4766 -5.0938 Q1.4219 -5.1875 1.3047 -5.2344 Q1.1875 -5.2812 0.9062 -5.2969 L0.9688 -5.6094 L2.3281 -5.6562 Z"
stroke="none"/>
</g>
<g color-interpolation="linearRGB" color-rendering="optimizeQuality"
image-rendering="optimizeQuality"
text-rendering="optimizeLegibility"
transform="translate(33.9207,7.3281)">
<path
d="M3.0781 -0.7031 Q3.2969 -0.7031 3.4297 -0.7266 Q3.5625 -0.75 3.6406 -0.8125 Q3.7188 -0.875 3.7656 -0.9766 Q3.8125 -1.0781 3.8906 -1.2812 L4.2656 -1.2812 L4.1875 0 L0.5625 0 L0.5625 -0.2188 Q0.75 -0.6719 1.0703 -1.1562 Q1.3906 -1.6406 1.9844 -2.2969 Q2.5 -2.8594 2.7188 -3.1406 Q2.9688 -3.4688 3.0859 -3.6953 Q3.2031 -3.9219 3.2578 -4.125 Q3.3125 -4.3281 3.3125 -4.5469 Q3.3125 -4.875 3.2109 -5.125 Q3.1094 -5.375 2.8906 -5.5234 Q2.6719 -5.6719 2.3438 -5.6719 Q1.5156 -5.6719 1.2344 -4.75 L0.7031 -4.75 L0.7031 -5.5938 Q1.2344 -5.8438 1.6953 -5.9531 Q2.1562 -6.0625 2.5312 -6.0625 Q3.3438 -6.0625 3.7578 -5.7109 Q4.1719 -5.3594 4.1719 -4.6719 Q4.1719 -4.4375 4.1328 -4.2422 Q4.0938 -4.0469 3.9922 -3.8594 Q3.8906 -3.6719 3.7266 -3.4453 Q3.5625 -3.2188 3.3594 -2.9922 Q3.1562 -2.7656 2.6562 -2.25 Q1.8125 -1.3594 1.4219 -0.7031 L3.0781 -0.7031 Z"
stroke="none"/>
</g>
</g>
</svg>
</fo:instream-foreign-object>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Now, if I apply an XSL to that which just copies everything and grabs the width and height of the SVG to use as the page-width and page-height.
This XSL would copy dimensions for the SVG and use them as page-width, page-height in the FO:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="svg" version="1.0">
<xsl:template match="fo:simple-page-master">
<fo:simple-page-master>
<xsl:apply-templates select="#*"/>
<xsl:attribute name="page-width">
<xsl:value-of select="concat(//*[namespace-uri()='http://www.w3.org/2000/svg' and local-name()='svg'][1]/#width,'px')"/>
</xsl:attribute>
<xsl:attribute name="page-height">
<xsl:value-of select="concat(//*[namespace-uri()='http://www.w3.org/2000/svg' and local-name()='svg'][1]/#height,'px')"/>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</fo:simple-page-master>
</xsl:template>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I would get this output in the page template (abbreviated only showing the page-master):
<fo:simple-page-master master-name="my-page" page-width="39px" page-height="11px">
<fo:region-body/>
</fo:simple-page-master>
As you can see, the page-width and page-height is set to the dimensions of the SVG.
This process chain would allow you to the format that to a page that is the size of the SVG (as calculated by JEuclid).
The result is this:
I have following XML.
<?xml version="1.0" encoding="utf-8"?>
<ordersPack id="1398720518" ic="12345678" application="Web" version="2.0" note="user">
<orderPackItem id="2014042847">
<order>
<orderHeader>
<numberOrder>2014042847</numberOrder>
<partnerIdentity>
<billing>
<firstname>Ilona</firstname>
<surname>Kokerková</surname>
</billing>
</partnerIdentity>
</orderHeader>
<orderDetail>
<orderItem>
<name><![CDATA[Kokosový panenský olej 1000 ml]]></name>
<unitPriceWithTax>290.00</unitPriceWithTax>
</orderItem>
<orderItem>
<name><![CDATA[Dobírka ČP - Balík na poštu]]></name>
<quantity>1</quantity>
<percentVAT>21</percentVAT>
<unitPrice>86.78</unitPrice>
<unitPriceWithTax>105.00</unitPriceWithTax>
</orderItem>
</orderDetail>
<orderSummary>
</orderSummary>
</order>
</orderPackItem>
<orderPackItem id="2014042846">
<order>
<orderHeader>
<orderType>receivedOrder</orderType>
<partnerIdentity>
<billing>
<firstname>David</firstname>
<surname>Liala</surname>
</billing>
</partnerIdentity>
</orderHeader>
<orderDetail>
<orderItem>
<name><![CDATA[Mikula Bio Mladý ječmen prášek 250 g]]></name>
<unitPriceWithTax>469.00</unitPriceWithTax>
</orderItem>
<orderItem>
<name><![CDATA[osobní odběr Brno, Orlí 16, AWA centrum]]></name>
<unitPriceWithTax>0.00</unitPriceWithTax>
</orderItem>
</orderDetail>
<orderSummary>
</orderSummary>
</order>
</orderPackItem>
</ordersPack>
I need exclude all items with <dat:dataPackItem> if <inv:text>Hotově, osobní odběr</inv:text> contain "Hotově, osobní odběr".
And desire output is :
<?xml version="1.0" encoding="windows-1250"?>
<dat:dataPack id="fa002" ico="12345678" application="StwTest" version="2.0" note="FA" ">
<dat:dataPackItem id="2014042847" version="2.0">
<inv:invoice version="2.0">
<inv:invoiceHeader>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
</inv:accounting>
<inv:classificationVAT>
<typ:ids>UD</typ:ids>
</inv:classificationVAT>
<inv:partnerIdentity>
<typ:address>
<typ:company>firma</typ:company>
<typ:division>Obchodní oddělení</typ:division>
<typ:name>IlonaKokerková</typ:name>
</typ:address>
</inv:partnerIdentity>
<inv:paymentType>
<typ:paymentType>delivery</typ:paymentType>
</inv:paymentType>
<inv:account>
<typ:ids>KB</typ:ids>
</inv:account>
<inv:intNote>Faktura s textovou a skladovou položkou</inv:intNote>
</inv:invoiceHeader>
<inv:invoiceDetail>
<inv:invoiceItem>
<inv:text>Kokosový panenský olej 1000 ml</inv:text>
<inv:homeCurrency>
<typ:unitPrice>290.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids>awa1265</typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
<inv:invoiceItem>
<inv:text>Dobírka zboží</inv:text>
<inv:homeCurrency>
<typ:unitPrice>0.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids></typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
<inv:invoiceItem>
<inv:text>Dobírka ČP - Balík na poštu</inv:text>
<inv:homeCurrency>
<typ:unitPrice>105.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids></typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
</inv:invoiceDetail>
</inv:invoice>
</dat:dataPackItem>
</dat:dataPack>
I need exclude all items with <dat:dataPackItem> if <inv:text>Hotově, osobní odběr</inv:text> contain "Hotově, osobní odběr".
How to do it?
Here is my XSLT....
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" encoding="windows-1250" />
<xsl:template match="/">
<dat:dataPack id="fa002" ico="12345678" application="StwTest" version = "2.0" note="Import FA">
<xsl:for-each select="ordersPack/orderPackItem">
<dat:dataPackItem id="{order/orderHeader/numberOrder}" version="2.0">
<!-- faktura bez adresy s textovou a skladovou polozkou-->
<inv:invoice version="2.0">
<inv:invoiceHeader>
<inv:symVar>
<xsl:value-of select="order/orderHeader/numberOrder"/>
</inv:symVar>
<inv:numberOrder>
<xsl:value-of select="order/orderHeader/numberOrder"/>
</inv:numberOrder>
<inv:dateOrder>
<xsl:value-of select="order/orderHeader/dateFrom"/>
</inv:dateOrder>
<inv:partnerIdentity>
<typ:address>
<typ:company>firma</typ:company>
<typ:division>Obchodní oddělení</typ:division>
<typ:name>
<xsl:value-of select="order/orderHeader/partnerIdentity/billing/firstname"/>
<xsl:value-of select="order/orderHeader/partnerIdentity/billing/surname"/>
</typ:name>
</typ:address>
</inv:partnerIdentity>
<inv:paymentType>
<typ:paymentType>
<xsl:choose><xsl:when test="order/orderDetail/orderItem/name='Dobírka zboží'">delivery</xsl:when>
<xsl:otherwise>draft</xsl:otherwise></xsl:choose>
</typ:paymentType>
</inv:paymentType>
<inv:account>
<typ:ids>KB</typ:ids>
</inv:account>
<inv:note>Načteno z XML</inv:note>
<inv:intNote>Faktura s textovou a skladovou položkou</inv:intNote>
</inv:invoiceHeader>
<inv:invoiceDetail>
<!--skladova polozka-->
<xsl:for-each select="order/orderDetail/orderItem">
<inv:invoiceItem>
<inv:text>
<xsl:value-of select="name"/>
</inv:text>
<inv:quantity>
<xsl:value-of select="quantity"/>
</inv:quantity>
<inv:payVAT>true</inv:payVAT>
<xsl:choose>
<xsl:when test="percentVAT = '15'">
<inv:rateVAT>low</inv:rateVAT>
</xsl:when>
<xsl:when test="percentVAT = '21'">
<inv:rateVAT>high</inv:rateVAT>
</xsl:when>
</xsl:choose>
<inv:homeCurrency>
<typ:unitPrice>
<xsl:value-of select="unitPriceWithTax"/>
</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids>
<xsl:value-of select="product_nr"/>
</typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
</xsl:for-each>
</inv:invoiceDetail>
</inv:invoice>
</dat:dataPackItem>
</xsl:for-each>
</dat:dataPack>
</xsl:template>
</xsl:stylesheet>
You need to think in terms of the input, not the output. If you want to exclude all orderItem elements whose name includes "Hotově, osobní odběr" then you need to add a predicate to the orderItem for-each:
<!--skladova polozka-->
<xsl:for-each select="order/orderDetail/orderItem[not(contains(name, 'Hotově, osobní odběr'))]">
To completely remove any orderPackItem that contains any orderItem with this text you need the predicate at the top level:
<xsl:for-each select="ordersPack/orderPackItem[
not(order/orderDetail/orderItem[
contains(name, 'Hotově, osobní odběr')])]">
This is all about reverse a string. It works properly for the given Value 'ABCDEF'. The output is also correct 'FEDCBA'. But I want to know how this is printing letters 'A' and 'D' in this string. Could anyone help me to understand this? please.
Elaborate this working method.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:output method="html"/>
<xsl:template name="reverse">
<xsl:param name="input" select="'ABCDEF'"/>
<xsl:variable name="len" select="string-length($input)"/>
<xsl:choose>
<xsl:when test="$len < 2">
<xsl:value-of select="$input"/>
</xsl:when>
<xsl:when test="$len = 2">
<xsl:value-of select="substring($input,2,1)"/>
<xsl:value-of select="substring($input,1,1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="mid" select="floor($len div 2)"/>
<xsl:call-template name="reverse">
<xsl:with-param name="input" select="substring($input,$mid+1,$mid+1)"/>
</xsl:call-template>
<xsl:call-template name="reverse">
<xsl:with-param name="input" select="substring($input,1,$mid)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="reverse">
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
Here's what happens:
Input ABCDEF
len = 6
len is > 2 and not = 2
mid = 3
Call again with input DEF
len = 3
len is > 2 and not = 2
mid = 1
Call again with input EF
len = 2
len is not > 2 but = 2
Put out the second letter F
Put out the first letter E
Return to outer call
Call with input = D
len is less than 2
Output D
Return to outer call
Call again with input = ABC
len = 3
len is > 2 and not 2
mid = 1
Call again with input BC
len = 2
len is not > 2 but = 2
Put out the second letter C
Put out the first letter B
Return to outer call
Call with input A
len is less than 2
Output A