Increase xml:id with 1 find/replace with notepad++ - regex

a simple but short question. I am using notepad++ for my xml sheet. Heres is an example structure.
<category xml:id="S0078">
<catDesc>
<term>Test</term>
</catDesc>
</category>
<category xml:id="S0079">
<catDesc>
<term>Test</term>
</catDesc>
</category>
My question is how can i increase the id from S0078 to S300 by one with an simple search and replace command. I tried to use regular expression. but this was not working. Anyone have an idea ?

Use an XML aware tool to modify XML. For example, in xsh, you can do
open file.xml ;
for my $id in //category[
(#xml:id | preceding-sibling::category/#xml:id) = 'S0078'
][
(#xml:id | following-sibling::category/#xml:id) = 'S0300'
]/#xml:id
set $id/. { $id->value =~ s/([0-9]+)/$1+1/er } ;
save :b ;

Related

Specific string use as attribute n XSLT

I have a String //hdfhddf/vgbgb/erer/nhnhn//<std-der>/figure.jpg. I want to filter only fig_1.eps and use it as a attribute in XSLT.
output should be :
<image ref="fig_1.eps" />
Assuming you can use XSLT 2.0, I would suggest:
tokenize($yourstring, '/')[last()]
There is a likely a shorter regex-only option, but I prefer readability.

XSL-FO | FO: Tags are being removed

I'm currently using XSL for a work project and I'm facing an issue.
I'm trying to read values for a database that look like this:
<fo:block font-weight='bold>hello</fo:block>
and it seems that XSL is stripping the <fo:block> element because it gives me text only ( I only see Hello, not in bold, and it doesn't behave like a block element ). I feel like, somehow, that XSL interprets the value read from the DB as a string, and strip of the <fo> tags, leaving my with text only.
Any idea what could be done in order that my styling get preserved?
( Obviously this example have been simplified, the text to be displayed is longer than that )
EDIT : Self answered for future references
Based on the comments you want to change <xsl:value-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription'/> to <xsl:copy-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription'/> (or perhaps <xsl:copy-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription/node()'/>).
As first i wanted to thanks you all to have taken the time to answer me. I'm very very very glad to see SO community is such strong.
I have solved my problem this way :
<xsl:for-each select="/fulfill-list/ticket-list/list-item/eventTicketContent/xmlTicketContent/ticketdescription/node()">
<xsl:copy-of select="child::node()" />
</xsl:for-each>
I don't really know what happened beneath the hood and why the <fo> tags were removed, but they were. Looping through all of them and using <xsl:copy-of> did the trick.
Once again, a big thanks to y'all !

Excel Print command, creating text template

Hi I am new to VBA and was looking to output my Excel sheet data into a text template. So far all I have been able to do is output the data but I don't know where to go from there. What I have:
Private Sub CommandButton1_Click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = "C:\Users\Francis\Desktop\redirect.txt"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
I wish to change this so the text output isn't just "celldataA*" "celldataB*" etc.
I want to make it so that the document starts with
<rule> and ends with </rule>
Then each row would come out as
<rule name="Rule rownumber*" patternSyntax="ExactMatch" stopProcessing="true">
<match url="celldataA*" />
<action type="Redirect" url="celldataB*" />
</rule>
Any pointers? It's that or I manually do it myself 3.5k times so any help at all is welcome.
These resources on generating XML from Excel should help you.
MS Office.Com: Create an XML data file and XML schema file from worksheet data
MSDN Library: Creating an XML Mapping Schema in Excel 2010
Mr Excel: Using XML in Excel 2003
essentially you create a schema file then output the xml data using that schema to define the data.

xsl - select node by child

I have a problem selecting just elements of an xml, which contain a specific child node. Asumme the following part of an xml:
<root>
<Navision.Buchungen>
<Saldo>-110867.7500</Saldo>
<Navision.Kontostruktur>
<Bereich>1</Bereich>
</Navision.Kontostruktur>
</Navision.Buchungen>
<Navision.Buchungen>
<Saldo>-3082585.2100</Saldo>
<Navision.Kontostruktur>
<Bereich>2</Bereich>
</Navision.Kontostruktur>
</Navision.Buchungen>
...
</root>
Now I have an xsl part like this to get the sum of 'Saldo':
<xsl:variable name="FACT0" select="sum(//root/Navision.Buchungen/Saldo)"/>
But how can I select just the Saldo for 'Bereich' 1 for example?
Use this XPath:
//root/Navision.Buchungen[Navision.Kontostruktur/Bereich = 1]/Saldo
//root/Navision.Buchungen[Navision.Kontostruktur/Bereich = 1]/Saldo
Edited:
oh already posted.
For further problems you can use one of the online testbeds like this one. And of course good manuals like those from w3schools, also with testbeds for xsl

libxml2 XPATH - Selecting subset of data from XML

I am fairly new to XML dev.. I had a few questions regarding XML parsing with XPATH and libxml.
I have an XML structured as :
<resultset>
<result count=1>
<row>
<name> He-Man! </name>
<home> Greyskull </home>
<row>
</result>
<result count=2>
<row>
<name> Spider-Man</name>
<home> Some downtown apartment </home>
<row>
<row>
<name> Disco-Man!</name>
<home> The 70's dance floor </home>
<row>
</result>
<resultset>
I need to pick out the names from this XML , but where the count is 2 , i need it only from the first record. I ran through a few tutorials, but i am unable to come up with an XPATH query which would serve this purpose.
/name will select all name elements.
/result[#count > 1 ]/row[1]/name | /result[#count =1 ]/row/name
Is this possible to be done with XPATH ? Is this better to be done via XPATH or by walking the XML tree?
Can some one point me to some complex searches through out XML's ?
Edit : The actual scenario requires select a subset of the XML row , which are nested at 2 levels at times. This sounds like i need to OR '|' many paths to select the nodes i require... I am not sure if that would be efficient as opposed to walking a tree... The above is typed to replicate the problem :)
Thanks!
Try this XPath -
/resultset/result[#count=2]/row/name
This will give a list of all nodes falling under this XPath. From this just take the first element (as you needed only the first record).
I'd probably keep my xpath simpler and just extract both cases, then loop over both node sets.
If you do need to go down the single xpath route, you should try out your xpath expressions in something that lets you enter them live, rather than having to recompile C/C++ code. You should be able to do that by loading your XML into firefox and using firebug - for example typing $x('//name') in the firebug console gives three nodes.
NOTE however that your XML is invalid... You have a bunch of "<row>"s that should be "</row>" and the same for "<resultset>" and your counts need to be
<result count="1">
i.e. with quote marks around the value.