I'm currently using Biztalk for mapping. I have a source order document that contains all parts that are being ordered. The destination document needs to contain only rows that contain a valid item (CELL/#C004) in Valid/Sku list. The valid SKU list is cached on the webserver and gets refreshed as necessary. Rather than hardcoding the list of valid parts in the map, I'm using a c# script to call the webservice and the valid sku data is mapped into a xslt variable. Is this a good approach?
The best solution I'm thinking of right now is iterating over all of the Row data <xslt:for-each select"/SOURCE/ROWS/ROW"> and then doing a check to see if the item is in the list of valid items. Is there a more efficent way to do this? something equivelant to select ROW/CELL[#Name='C004'] IN valid/sku list?
Source Document
<SOURCE>
...other nodes
<ROWS>
<ROW type="D" index="0 ">
<CELL name="C001" visible="X">
<VALUE>80710693</VALUE>
</CELL>
<CELL name="C002" visible="X">
<VALUE>10</VALUE>
</CELL>
<CELL name="C003" visible="X">
<VALUE>100100</VALUE>
</CELL>
<CELL name="C004" visible="X">
<VALUE>04001-17</VALUE>
</CELL>
<CELL name="C005" visible="X">
<VALUE decimals="3">100.000</VALUE>
</CELL>
</ROW>
<ROW type="D" index="0 ">
<CELL name="C001" visible="X">
<VALUE>80710693</VALUE>
</CELL>
<CELL name="C002" visible="X">
<VALUE>10</VALUE>
</CELL>
<CELL name="C003" visible="X">
<VALUE>100100</VALUE>
</CELL>
<CELL name="C004" visible="X">
<VALUE>05001-17</VALUE>
</CELL>
<CELL name="C005" visible="X">
<VALUE decimals="3">100.000</VALUE>
</CELL>
</ROW>
</ROWS>
</SOURCE>
list of valid values (about 1,500 values) from a webservice call.
<Valid>
<Sku>04001-17</<Sku>
<Sku>04002-17</<Sku>
<Sku>04003-17</<Sku>
</Valid>
XPath would be /SOURCE/ROWS/ROW[CELL[#name = 'C004']/VALUE = $skus/Valid/Sku] or with XSLT 2 or 3 I would define a key <xsl:key name="sku" match="Valid/Sku" use="."/> and use the path /SOURCE/ROWS/ROW[key('sku', CELL[#name = 'C004']/VALUE, $sku)].
Related
I have a special case because I need to check current value with preceding one.
In some cases the tag doesn't contain a value.
Sample XML:
<Row>
<Cell column="Contrat">
<Type>String</Type>
<Value>blabla</Value>
</Cell>
<Cell column="Dossier">
<Type>String</Type>
<Value>monitoring</Value>
</Cell>
<Cell column="DocVersion" />
<Cell column="CodeAffaire">
<Type>String</Type>
<Value>AF1302740</Value>
</Cell>
</Row>
In this case how can i detect that the tag DocVersion is without a value ?
I am matching all date formats in my file using the regex ([0-9]+)-+([0-9]+)-+([0-9]+) now how can i delete everything else but the matches? Thanks
Here is an example
<Data ss:Type="String">2017-03-10 15:57:34</Data>
</Cell>
<Cell>
<Data ss:Type="String">0</Data>
</Cell>
<Cell>
<Data ss:Type="String">Evelyne</Data>
</Cell>
<Cell>
<Data ss:Type="String">Evelyne</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="String">170212</Data>
</Cell>
<Cell>
<Data ss:Type="String">everest</Data>
</Cell>
<Cell>
<Data ss:Type="String">everest</Data>
</Cell>
<Cell>
<Data ss:Type="String">sdfsd#gmail.com</Data>
</Cell>
<Cell>
<Data ss:Type="String"></Data>
</Cell>
<Cell>
<Data ss:Type="String">2017-04-29 10:21:09</Data>
I need to delete everything but the dates in Sublime using mac, thanks.
In the menu: Find -> Find
Enter your regex, then press FindAll
In the menu: Edit -> Copy
Delete contents of the file
In the menu: Edit -> Paste
I want to monitor + export in/out traffic data to XML with MRTG and rrdtool xport. I have several problems:
The exported XML has the same timestamp for start and end in the meta section. I specified --start 1429862400 --end 1429894800, the output values start at 1429862700 and end at 1429886100, also I'm getting quite a few NaNs.
I mapped ds0 and ds1 to my in/out variables, but I'm not actually sure where to define ds's in the first place. How can I map my variables to network in and out traffic? Where are the ds-devices configured?
Ds1, probably because not properly configured, produces faulty values.
I'm running
rrdtool xport\
DEF:out_bytes=localhost_2.rrd:ds0:AVERAGEDEF:in_bytes\
=localhost_2.rrd:ds1:AVERAGE CDEF:io_bytes=out_bytes,in_bytes,+\
XPORT:in_bytes:outbytes XPORT:out_bytes:inbytes XPORT:io_bytes:iobytes\
--enumds --start 1429862400 --end 1429894800
to export.
This is my mrtg.cfg
WorkDir: /var/www/mrtg/graph
WriteExpires: Yes
Title[^]: Traffic Analysis for
EnableIPv6: no
Target[localhost_2]: 2:public#127.0.0.1:
SetEnv[localhost_2]: MRTG_INT_IP="No Ip" MRTG_INT_DESCR="eth0"
MaxBytes[localhost_2]: 1250000
Title[localhost_2]: Traffic Analysis for 2 -- SMDSP01
XSize[localhost_2]: 256
YSize[localhost_2]: 64
XScale[localhost_2]: 0.65
YScale[localhost_2]: 0.6
Unscaled[localhost_2]: d
WithPeak[localhost_2]: d
Here's a snipped of the output
<?xml version="1.0" encoding="UTF-8"?> <xport> <meta>
<start>1429862700</start>
<step>300</step>
<end>1429862700</end>
<rows>109</rows>
<columns>3</columns>
<legend>
<entry>outbytes</entry>
<entry>inbytes</entry>
<entry>iobytes</entry>
</legend> </meta> <data>
<row>
<t>1429862700</t>
<v0>7.5489722222e+00</v0>
<v1>1.4522986944e+05</v1>
<v2>1.4523741842e+05</v2>
</row>
<row>
<t>1429863000</t>
<v0>9.3254770432e+00</v0>
<v1>1.6219456095e+05</v1>
<v2>1.6220388643e+05</v2>
</row>
<row>
<t>1429863300</t>
<v0>6.4311896235e+00</v0>
<v1>1.6358109508e+05</v1>
<v2>1.6358752627e+05</v2>
</row>
<row>
<t>1429863600</t>
<v0>9.8945000000e+00</v0>
<v1>4.6888782408e+05</v1>
<v2>4.6889771858e+05</v2>
</row>
<row>
<t>1429863900</t>
<v0>5.6088333333e+00</v0>
<v1>4.2072387378e+05</v1>
<v2>4.2072948261e+05</v2>
</row>
<row>
<t>1429864200</t>
<v0>2.0383366480e+01</v0>
<v1>2.5505514117e+05</v1>
<v2>2.5507552453e+05</v2>
</row>
<row>
<t>1429864500</t>
<v0>1.2132332724e+03</v0>
<v1>2.1026807079e+06</v1>
<v2>2.1038939412e+06</v2>
</row>
<row>
<t>1429864800</t>
<v0>2.3604750000e+01</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429865100</t>
<v0>6.3642958611e+03</v0>
<v1>1.1198971143e+07</v1>
<v2>1.1205335438e+07</v2>
</row>
<row>
<t>1429865400</t>
<v0>1.5586544194e+04</v0>
<v1>8.5607161284e+06</v1>
<v2>8.5763026726e+06</v2>
</row>
<row>
<t>1429865700</t>
<v0>2.4014277778e+01</v0>
<v1>3.3303833329e+06</v1>
<v2>3.3304073472e+06</v2>
</row>
...
<row>
<t>1429892100</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429892400</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429892700</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429893000</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429893300</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429893600</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429893900</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429894200</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429894500</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429894800</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row>
<row>
<t>1429895100</t>
<v0>NaN</v0>
<v1>NaN</v1>
<v2>NaN</v2>
</row> </data> </xport>
Thanks for your help!
Firstly, the invalid <end> tag in the XML output is a bug in RRDTool. You do not say which version you are using, but if you are not using the latest, please upgrade. If you ARE using the latest, please report a bug :)
The output time points are slightly off from your requested window because of fenceposting. You're specifying the data points, and are exporting the RRA containing them (which will end 1 step later). This is a bit counterintuitive but I think it is by design.
You are defining your variable DEFs from your RRD DSs thus:
DEF:out_bytes=localhost_2.rrd:ds0:AVERAGE
DEF:in_bytes=localhost_2.rrd:ds1:AVERAGE
An RRD file generated by MRTG will always have exactly two DSs -- called ds0 and ds1. Although RRDTool can support many more DSs with all sorts of names, you cannot change the names in an MRTG-generated RRD file, not can you add or remove a DS, without breaking MRTG. If you want to have more DSs, the only way to do it is to add a new MRTG Target -- which will create a new RRD file, with DSs 'ds0' and 'ds1' -- and then add this to your Xport request as an addiitonal two DEF lines.
The NaNs are where the underlying RRA does not have valid data. This is likely because there simply has not been (enough) data collected for that time window, or the collected data were invalid. The corresponding MRTG graphs will likely show nothing as well. Another possibility is that the wrong RRA is being selected, but this is unlikely as your time window is only 9hr which fits fine into the default 1-day high-granularity RRA generated by MRTG.
If your values are faulty, then verify that they are not faulty in the RRD already - xport only outputs what is in the database. Are you expecting an output in Bits and not Bytes (in which case multiply by 8)? Are you values around 140Mbps (IE 18MBps) but you are querying via SNMPv1 in which case MRTG is unable to poll the data? In this case, use SNMPv2 with MRTG to fetch the correct data. Unfortunately you have not given any details how the data are 'faulty' so I can only speculate.
I am trying to write XSLT file for following input XML to output XML, is it possible XSLT to convert the value of input xml as node in output XML? how can I implement this?
Input XML
<?xml version="1.0" encoding="UTF-8"?>
<Rows>
<Row><xml_data_name/> <xml_data_value/> </Row>
<Row><xml_data_name>persons</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>person</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>username</xml_data_name> <xml_data_value>JS1</xml_data_value> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value>John</xml_data_value> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value>Smith</xml_data_value> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>person</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>person</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>username</xml_data_name> <xml_data_value>MI1</xml_data_value> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value>Morka</xml_data_value> </Row>
<Row><xml_data_name>name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value>Ismincius</xml_data_value> </Row>
<Row><xml_data_name>family-name</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>person</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name>persons</xml_data_name> <xml_data_value/> </Row>
<Row><xml_data_name/> <xml_data_value/> </Row>
</Rows>
Output XML
<?xml version="1.0" ?>
<persons>
<person username="JS1">
<name>John</name>
<family-name>Smith</family-name>
</person>
<person username="MI1">
<name>Morka</name>
<family-name>Ismincius</family-name>
</person>
</persons>
You could certainly use xsl:element like
<xsl:template match="Row">
<!-- Note {} brackets in name attribute -->
<xsl:element name="{xml_data_name}">
<xsl:value-of select="xml_data_value" />
</xsl:element>
</xsl:template>
What would be greater problem is a structure of output because it is not easy to decide which rows should be nested, which rows should transform into an attribute rather than element etc.
Well, that's one of the weirdest data formats I've ever seen! Are you sure you can't get whatever produced this to produce something more reasonable?
I think the solution has to be recursion: you want a function that takes a sequence of rows as input; it outputs an element whose name is the name of the first element in the sequence with no data value and whose content is obtained by a recursive call that passes all rows after that first row up to the next row with no data value and the same name, then calls itself to process all rows after that row. Not easy, and certainly takes more time than I allow myself for answering SO questions!
I have been banging my head against a wall on this for a while. Our application processes a complex structure XML invoice from another system. The invoice contains rows of information which contain various counts. These counts may or may not contain a value. There is an overall document charge. We need to work out the unit charge. The formula would be the total cost divided by the total of the counts.
I have been working through the examples kindly provided by others regarding summing in XSLT1.0. I can use xsl:call-template to get the sum of the counts, but I don't know how to apply the result to the calculate the unit price.
Sample XML
<Document>
<Row>
<Count1>
<Value>10</Value>
</Count1>
<Count2>
<Value/>
</Count2>
</Row>
<Row>
<Count1>
<Value>5</Value>
</Count1>
<Count2>
<Value>6</Value>
</Count2>
</Row>
<Row>
<Count1>
<Value>2</Value>
</Count1>
<Count2>
<Value>3</Value>
</Count2>
</Row>
<Charge>
<Value>260</Value>
</Charge>
</Document>
If I could see how to get the following XML output that would probably show me what I need.
<Document>
<Row>
<Total>10</Total>
<UnitPrice>10</UnitPrice>
</Row>
<Row>
<Total>11</Total>
<UnitPrice>10</UnitPrice>
</Row>
<Row>
<Total>15</Total>
<UnitPrice>10</UnitPrice>
</Row>
</Document>
Many thanks in advance
You just need to call sum() on the required Values, like so:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Document">
<Document>
<xsl:apply-templates select="Row"/>
</Document>
</xsl:template>
<xsl:template match="Row">
<Row>
<Total>
<xsl:value-of select="sum(./*[Value>0]/Value)"/>
</Total>
<UnitPrice>10</UnitPrice>
</Row>
</xsl:template>
</xsl:stylesheet>
This gives the output:
<Document>
<Row>
<Total>10</Total>
<UnitPrice>10</UnitPrice>
</Row>
<Row>
<Total>11</Total>
<UnitPrice>10</UnitPrice>
</Row>
<Row>
<Total>5</Total>
<UnitPrice>10</UnitPrice>
</Row>
</Document>