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
Related
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)].
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 have this XML-structure where I would like to match the individual data-elements elements that have the ###DoNotUse### string inside.
In the example, it should match the data elements C and E.
But my RegEx also matches all data-elements before the matches that I require, meaning A+B+C instead of just C, and D+E instead of just E.
I appreciate your help very much.
My RegEx is:
<data(.*?)###DoNotUse###(.*?)</data>
The example data is:
<data name="A">
<value>A</value>
<comment>Bla Bla</comment>
</data>
<data name="B">
<value>B</value>
</data>
<data name="C">
<value>###DoNotUse###</value>
<comment>Bla Bla</comment>
</data>
<data name="D">
<value>D</value>
<comment>Bla Bla</comment>
</data>
<data name="E">
<value>###DoNotUse###</value>
</data>
You are looking for :
(?s)<data name="([^"]*)">(?:(?!data).)*DoNotUse
The (?s) is for single line mode. You can find the demonstration and explanations HERE: DEMO
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>
I have two source xml files and I need to construct a new xml file which contains elements chosen for one or other of the files depending on whether their 'name' is contained in a plain text file.
xml file a:
<data name="name1">
<value>abc1</value>
</data>
<data name="name2">
<value>abc2</value>
</data>
<data name="name3">
<value>abc3</value>
</data>
xml file b:
<data name="name1">
<value>xyz1</value>
</data>
<data name="name2">
<value>xyz2</value>
</data>
<data name="name3">
<value>xyz3</value>
</data>
text file:
name1
name3
desired output:
<data name="name1">
<value>abc1</value>
</data>
<data name="name2">
<value>xyz2</value> <---- note this element is from file 'b'
</data>
<data name="name3">
<value>abc3</value>
</data>
So the elements with names 'name1' and 'name3' come from 'xml file a' because they are listed in the text file, but 'name2' comes from 'xml file b' because it isn't.
The actual names aren't 'name1' etc, but arbitrary string identifiers, but they are unique within the files.
Is it possible to do this with XSLT?
This transformation:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vNames" select=
"tokenize(unparsed-text('file:///c:/temp/delete/Names.txt'), '\s')"/>
<xsl:variable name="vDoc1" select="document('file:///c:/temp/delete/FileA.xml')"/>
<xsl:variable name="vDoc2" select="document('file:///c:/temp/delete/FileB.xml')"/>
<xsl:template match="/">
<t>
<xsl:sequence select=
"$vDoc1/*/*[#name = $vNames],
$vDoc2/*/*[not(#name = $vNames)]
"/>
</t>
</xsl:template>
</xsl:stylesheet>
when applied on any XML document (not used) and having these two files:
c:/temp/delete/FileA.xml:
<t>
<data name="name1">
<value>abc1</value>
</data>
<data name="name2">
<value>abc2</value>
</data>
<data name="name3">
<value>abc3</value>
</data>
</t>
c:/temp/delete/FileB.xml:
<t>
<data name="name1">
<value>xyz1</value>
</data>
<data name="name2">
<value>xyz2</value>
</data>
<data name="name3">
<value>xyz3</value>
</data>
</t>
c:/temp/delete/Names.txt:
name1
name3
produces the wanted, correct result:
<t>
<data name="name1">
<value>abc1</value>
</data>
<data name="name3">
<value>abc3</value>
</data>
<data name="name2">
<value>xyz2</value>
</data>
</t>
Explanation:
Proper use of the standard XSLT functions: unparsed-text() (2.0 and up only) and document() and the standard XPath 2.0 function tokenize()
While XSLT can output plain text, the input document is expected to be XML. However, it's possible to mix in Java in your transformation. Personally, I'd add some java functions to open the file and process it in a grep-like fashion.
This general tutorial on adding Java functions to XSLT stylesheets would be a good start. It has the advantage of mentioning how-to's for some of the more common XSLT processing engines.
Here's a related discussion on SO