Say I have a node tree:
<data>
<current-query-string><![CDATA[location=burnley]]></current-query-string>
</data>
How would I get the text only from inside the CDATA tags?
It's been a very long time since I wrote xslt at this level, and I cannot remember how to do it. I understand that CDATA is plain text, and how it all works, just not how to extract the actual string only.
Simply using:
link
is giving me:
link
I expect that result, I need to see the result:
link
How do I use the value as plain text?
Related
Could anyone please help in getting the ampersand "&" output of Transform xml activity of TIBCO .
My requirement is the xmlstring from Transform xml activity is mapped to Parse xml (which will give the final output ) .Ex; Maitree&Sons. What should be passed in xslt so that when the output from Transform xml goes to Parse xml it will give the final result as "&".
I tried using CDATA and disable-escaping-output also in xslt but in parse xml it fails.
Please help.
Generally XSLT won't allow you to produce invalid output. The correct representation in XML is Maitree&Sons and this is what it produces. If it produced Maitree&Sons, this would be invalid XML and would be thrown out by an XML parser trying to read the document.
Having said that, it's possible using disable-output-escaping to produce an unescaped ampersand if your XSLT processor supports this option. If it's not working for you we need to know exactly what you did and how it failed.
(General rule: on SO, always tell us exactly what you did and exactly how it failed. Saying in general terms that you tried lots of things and none of them worked doesn't get us any nearer to a solution.)
LATER
I'm reading the question again. You want to produce output from the transformer that will go into an XML parser, such that the output of the parser is Maitree&Sons. Well, in that case the lexical XML must be Maitree&Sons, which it will be if you generate the string Maitree&Sons in XSLT. But XSLT is XML, so if you want to write this as a literal string in your stylesheet, it will be written Maitree&Sons.
I guess we need a much clearer picture of what you are doing and where it is going wrong.
I'm new to batch script. I want to replace a strings in a particular file.
In below script I'm getting error.
#echo off
$standalone = Get-Content 'C:\wildfly\standalone\configuration\standalone.xml'
$standalone -replace '<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>','<wsdl-host>${jboss.bind.address:0.0.0.0}</wsdl-host>' |
Set-Content 'C:\wildfly\standalone\configuration\standalone.xml'
The proper way to edit XML is to process it as an XML document, not as a string. That's because the XML file is not guaranteed to maintain specific formatting. Any edits should be context-aware and string replace isn't. Consider the three eqvivalent XML fragments:
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host >
<wsdl-host >${jboss.bind.address:127.0.0.1}</wsdl-host >
Note that whitespacing in element names is different and it's legal to add some. What's more, in practice, a lot of implementations simply discard line breaks in element values, so the two following are likely to provide same results to a config parser:
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
<wsdl-host>${jboss.bind.address:127.0.0.1}
</wsdl-host>
It really doesn't make much sense to process XML as string, does it?
Fortunately, Powershell has built-in support for XML files. A simple approach is like so,
# Mock XML config
[xml]$x = #'
<root>
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
</root>
'#
# Let's change the wsdl-host element's contents
$x.root.'wsdl-host' = '${jboss.bind.address:0.0.0.0}'
# Save the modified document to console to see the change
$x.save([console]::out)
<?xml version="1.0" encoding="ibm850"?>
<root>
<wsdl-host>${jboss.bind.address:0.0.0.0}</wsdl-host>
</root>
If you can't use Powershell and are stuck with batch scripts, you really need to use a 3rd party XML manipulation program.
I have an XML file with a lot of tweets and want to extract the text of every tweet which includes an Emoticon.
The XML file looks like this:
<root>
<tweet>
<id>573890929636941824</id>
<name>B&BeyondMagazine</name>
<text>Your Torrent Client May Be Mining Bitcoin Without Telling You http://t.co/xhTdmAYD20</text>
</tweet>
<tweet>
<id>573890929628614656</id>
<name>03/08</name>
<text>#8900Princess that's what I thought you was on off the rip , that's why I said why 😂</text>
</tweet>
</root>
So I need every text-tag value with an emoticon.
I would usually try to use a Regular Expression to identify the strings with Emoticons, but I read that you can't use RegEx with XML files.
How can I do that with an XML Parser (which one) or should I maybe extract all the tweets and use RegEx?
And after that I would have to extract all the Emoticons and count all the different types, any advice on that would be appreciated, too.
I am using XSLT to generate an .sql file from an .xml input file.
I have some problems with the indentation.
The way the stylesheet is formatted (how many line feeds and carriage returns and tabs) directly effects the output file i.e. if I include a few line feeds and CRs in my stylesheet to make it more readable, they are displayed in the output file as well (this would not be that bad if the tabs didn't affect the formatting of the output file as well):
It looks like this:
SQLStatement1<CR><LF>
<CR><LF>
<CR><LF>
SQLStatement2<CR><LF>
.... (tabs are also outputted)
I use an ant task to create the .sql file. The target looks like this:
<xslt in="input.xml"
out="queries.sql"
style="createQueries.xls">
</xslt>
I am using XSLT 1.0 and cannot use XSLT 2.0.
I thought about modifying some output parameters. However it does not have any effect if I change the method attribute to e.g. 'html' (I guess that the method is set to 'text' since the type of the output file(sql) is not known)
Any ideas on how to fix this issue?
Cheers
You would make it much easier on us if you showed a small but complete XML input sample, an XSLT sample, the output you get and the output you want.
If you use xsl:output method="text" and want to control the white space then make sure you use xsl:text to output literal text and xsl:value-of to output computed text. That way you should be able to control the white space exactly.
I'm writing a library that creates xml tree from given data.
The problem is that the data contains tags inside nodes.
for example
<node> "this is a very <bold>huge</bold> text" </node>
quotes - just to separate text given to me=)
When I create an xml using libxml and then write it to console (using xmlDumpMEmeory) I get:
<node>this is a very <bold>huge</bold> text</node>
I understand why it's so but have no ideas how to fix that normally.
The only solution I see is to manually replace < and > in my ::ToString()
But are there any other symbols (like <,>) that I should replace?
Thx for attention
If you wish to embed special characters such as this in the element contents, they need to be wrapped as CDATA. A conformant XML implementation will always do what you noticed here.
libxml should have some way to write element contents as CDATA that should fix this for you. This looks promising:
Function: xmlTextWriterWriteCDATA
Write an xml CDATA.