I cannot get qtwebkit to display css/xsl. I have tried both and they work in web browsers, but not in the qtwebkit. Is there a setting I need to enable to apply a stylesheet, or is this a downfall of the qtwebkit?
EDIT: XSLT support is disabled in Qt 4.7 (http://gitorious.org/webkit/qtwebkit/commit/8961d12)
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="status.xsl"?>
<hk>
<item><name>Some Parameter</name><value>value</value></item>
<item><name>Test Count</name><value>38</value></item>
</hk>
xsl (status.xsl)
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*|/">
<html><head>
<meta http-equiv="refresh" content="1"></meta></head>
<body> <h2>Status</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Parameter</th>
<th>Value</th>
</tr>
<xsl:for-each select="hk/item"> <tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="value"/></td>
</tr> </xsl:for-each> </table>
</body> </html> </xsl:template> </xsl:stylesheet>
QtWebKit
webView->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile("file.css"));
webView->load(QUrl("http://192.x.x.x:port/file.xml));
When viewing the URL in a browser the css looks fine... but not in webkit?
Related
I am trying to display the text of a hyperlink. The hyperlink is obtained from a query, and its column type is Publishing Hyperlink.
This code <xsl:value-of select="$Link" /> display the full link
File 1
How can I just display the text of the link?
File
Is there some code like <xsl:text-of select="$Link" /> or something else?
You can use
<xsl:value-of select="YOUR ANCHOR TEXT TAG IN XML HERE"/>
Replace your link text tag name you have given in your xml file with "YOUR ANCHOR TEXT TAG IN XML HERE"
This will display the anchor text for sure.
See the example below
XML Code
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<link>http://www.google.com</link>
<text>google</text>
</cd>
<cd>
<link>http://www.yahoo.com</link>
<text>yahoo</text>
</cd>
</catalog>
XSLT Code
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Anchor Link</th>
<th style="text-align:left">Anchor Text</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="link"/></td>
<td><xsl:value-of select="text"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Please click on the url to see output
https://i.stack.imgur.com/Dp24I.jpg
According DataSource details:
Source
Using:
<xsl:text-of select="$Link.desc" />
Should work.
I'm a beginning user of xslt and xpath. Using an xpath on a command line (Ubuntu 14.04) with a xml file works, but the very same xpath in an xslt file returns nothing. I'm working with Juniper Junos xml files. Any suggestions?
Thanks,
George
The xml file begins with:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/12.3R8/junos">
<interface-information xmlns="http://xml.juniper.net/junos/12.3R8/junos-interface" junos:style="normal">
<physical-interface>
<name>fe-0/1/0</name>
<logical-interface>
<name>fe-0/1/0.0</name>
...
The command line that works in Ubuntu 14.04 is:
xpath -e "/rpc-reply/interface-information/physical-interface/logical-interface/name" interfaces.xml
The xslt file is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Interfaces</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
</tr>
<xsl:for-each select="/rpc-reply/interface-information/physical-interface/logical-interface">
<tr>
<td><xsl:value-of select="name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The problem here is quite simple. You are not using namespaces in your XPaths. Apparently your command line utility doesn't care, or evaluates XPaths based on the elements' QNames ignores default namespaces and does some other non-standard handling of namespaces as well.
The solution:
Declare prefixes at the top of your stylesheet:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nbase="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junosi="http://xml.juniper.net/junos/12.3R8/junos-interface"
>
use those prefixes in your XPaths:
<xsl:for-each select="/nbase:rpc-reply/junosi:interface-information
/junosi:physical-interface/junosi:logical-interface">
<tr>
<td><xsl:value-of select="junosi:name"/></td>
</tr>
</xsl:for-each>
I have the following xml content in a file:
<testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540">
<properties>
<property name="comp1" value="0.0.0.0:80=0.0.1"/>
<property name="comp2" value="12.34.56.78:80=0.0.1"/>
and I want to create a table like
Name Value
comp1 0.0.0.0:80=0.0.1
comp2 12.34.56.78:80=0.0.1
with an xsl. I tried the following
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<xsl:for-each select="testsuite/properties/property">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
which just gives an empty table. How to do this correctly? I only found examples on the internet which were way to complex. If someone knows a good tutorial on such things, I am welcome as well.
# is used for attributes, if you don't use then it will be by default treated as an element..
so your code works fine if the XML is like this:
<testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540">
<properties>
<property>
<name>comp1</name>
<value>0.0.0.0:80=0.0.1</value>
</property>
<property>
<name>comp2</name>
<value>12.34.56.78:80=0.0.1</value>
</property>
..........
........
And here is your corrected code, observe the usage of #
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<xsl:for-each select="testsuite/properties/property">
<tr>
<td><xsl:value-of select="#name"/></td>
<td><xsl:value-of select="#value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Try
<td><xsl:value-of select="#name"/></td>
<td><xsl:value-of select="#value"/></td>
When accessing an attribute you need # before the name.
I am trying to extract data out of the following XML fragment:
<?xml version= "1.0" ?>
<Stmts xmlns="http://tempuri.org/Statement.xsd" Generation="2011-08-01T12:41:41" >
<StatementDetail AccountStatus="Open" CompanyID="" TransactionCount="182" >
<Transactions>
<Manual.../>
...
</Transactions>
</StatementDetail>
</Stmts>
Notice that the element has a xmlns attribute.
When I try to use the following XSL I get no data.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>CabCharge</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Batch</th>
<th>TransNo</th>
</tr>
<xsl:for-each select="Stmt/StatementDetail/Transactions/Manual">
<tr>
<td><xsl:value-of select="#Batch"/></td>
<td><xsl:value-of select="#TransNo"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
BUT! If I remove the XMLNS attribute from the element, I do get data.
What do I need to specifiy in the XSL to recognise the namespace???
Thanks.
Make sure to declare the default namespace of the document in your stylesheet, like:
<xsl:stylesheet version="1.0"
xmlns="http://tempuri.org/Statement.xsd"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Otherwise the XSLT processor will consider the elements referenced in your stylesheet as belonging to default namespace null.
Moreover, if you want the namespace exlcuded from the output document, you need to declare null namespace for the root literal element html, like:
<xsl:template match="/">
<html xmlns="">
<!-- your stuff -->
</html>
</xsl:template>
Do note also that:
In the xsl:for-each you are selecting the wrong element (Stmt in place of Stmts)
The attributes Batch and TransNo do not exist in your input documents.
I'm new to XSLT. I'm trying to change the font size of a specific text in XML file using XSLT. For eg- I have the CDCatalog.xml file with following data.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="cdcat.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist><SmallText>Bob Dylan</SmallText><LineBreak/>*</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
and the cdCat.XSL file is-
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:include href="cdCatalog.xsl" /> <!-- I added this -->
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:value-of select="title" />
</td>
<td>
<xsl:value-of select="artist" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I added a new xsl file cdCatalog.XSL file with following details-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="LineBreak">
<br/>
</xsl:template>
<xsl:template match="Superscript">
<sup>
<xsl:value-of select="."/>
</sup>
</xsl:template>
<xsl:template match="SmallText">
<font size="1">
<xsl:value-of select="."/>
</font>
</xsl:template>
</xsl:stylesheet>
and included this file in the CDCat.xsl file.and added the tags - <smallText>, <LineBreak> in the CdCatalog.xml file. now when I open the xml file i dont see the LineBreak nor the font size difference. Can anyone please suggest if I'm missing something.
Thanks in advance
Sai
You need to use apply-templates to indicate where your template matches should take effect.
XML says nothing about presentation, that's the whole point. It's a data format.
If you want your XSLT to output to something where presentation matters I suggest you transform to HTML and get let HTML/CSS handle the styling.
Having seen your actual code now (hint: use the formatting when creating questions) don't use the font tag. What you want semantically and in practice is just headers <h1>, <h2>, <h3> etc, and I'd still suggest you add a CSS link in there. Oh and <xsl:output method="html" />
In-between these two opening tags:
<html>
<body>
...I'd place a link to a style sheet that defines the font sizes. Alternatively (and useful if you want a self contained HTML file to email around) you could put a style block there instead.