Background color in some /row/entry informaltable - xpath

XML
XSLT
The problem I'm having is that when I export the XML file applying the stylesheets the syntax is correct, but it doesn't apply the background color to the cells of the informaltable.
The output method is and we are aplying "pdf" format to the final file (xmlns:fo).
Any ideas?
Thank you very much!.
We have tried to apply diferent codes and the result is always to obtain cells in white background color.
#MartinHonnen relevant code examples XSLT: <?xml version="1.0" encoding="UTF-8"?>
<?stylesheet-label Adasa's template for PDF and PostScript creation?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:d="http://docbook.org/ns/docbook"
version="1.0">
<xsl:import href="docbook5-config:xsl/fo/docbook.xsl"/>
<xsl:output method="xml"/>
<xsl:attribute-set name="table.table.properties">
<xsl:attribute name="border-before-width.conditionality">retain</xsl:attribute>
<xsl:attribute name="border-collapse">collapse</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="informaltable[#role='blue-table']">
<xsl:apply-templates mode="blue_table"/>
</xsl:template>
<xsl:template match="row/entry[1]/para" mode="blue_table">
<xsl:attribute name="background-color">#0E2F48</xsl:attribute>
<xsl:attribute name="color">#FF0000</xsl:attribute>
</xsl:template>
Relevant code examples XML:
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.1" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<title>Equipo de Trabajo</title>
<para>A continuación se describen las funciones y responsabilidades para cada uno de los perfiles que aparecen en la descripción de medios.</para>
<informaltable role="blue_table">
<tgroup cols="2">
<colspec colname="c1" colwidth="310*"/>
<colspec colname="c2" colwidth="690*"/>
<tbody>
<row>
<entry valign="middle">
<para>Delegado del Contratista</para>
</entry>

Related

Is there a way to conditionally sort in xslt?

I need to sort some content but only when an attribute is equal to CAT. I think I should be able to pass a property from my ant build file to the use-when attribute but it is not working. Any help would be appreciated
Here is the xslt that I have:
<xsl:for-each select="document(#fileRef)/foo/bar">
<xsl:sort select="translate(child::Title/text(), '>', '')" order="ascending" use-when="system-property('customerCode')='CAT'"
collation="http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive"/>
<!-- do some stuff here -->
</xsl:for-each>
Using oXygen I got the following to work in an Ant file:
<xslt in="sample1.xml" out="sample1-transformed.xml" force="true" style="sheet1.xsl">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
<sysproperty key="cat" value="bar"/>
</xslt>
XML sample1.xml is e.g.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>c</item>
<item>a</item>
</root>
XSLT is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:comment select="system-property('cat')"/>
<xsl:next-match/>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="item">
<xsl:sort select="." use-when="system-property('cat') = 'foo'"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
and then the output items are sorted only if the Ant sets e.g. <sysproperty key="cat" value="foo"/>.

How to add an image title in XSL?

I would like to add a title below each image. My xsl-file looks like this where I loop through each image:
<Testresult>
<xsl:for-each select="Testresult/image">
<img src="{#href}" width="333px" length="350px"/>
<title><xsl:value-of select="//Type"/></title>
<xsl:attribute name="src">
<xsl:value-of select="Testresult/Image"/>
</xsl:attribute>
</xsl:for-each>
</Testresult>
My xml-file looks like this:
<Testresult>
<image href="c:\image1.png"/>
<image href="c:\image2.png"/>
</Testresult>
The output should look like this:
thanks for the help!
try this stylesheet:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<Testresult>
<xsl:for-each select="Testresult/image">
<img src="{#href}" width="333px" length="350px"/>
<title><xsl:value-of select="#href"/></title>
</xsl:for-each>
</Testresult>
</xsl:template>
</xsl:stylesheet>

Sorting a table in XSLT 2.0

I have an index file, containing a list of xml files to process:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<part>
<numberGroup format="1" start="1">
<entry>
<file>04.xml</file>
<title>first file</title>
<css>stylesheet.css</css>
</entry>
<entry>
<file>05.xml</file>
<title>second file</title>
<css>stylesheet.css</css>
</entry>
<entry>
<file>06.xml</file>
<title>third file</title>
<css>stylesheet.css</css>
</entry>
.... more files
</numberGroup>
.... more NumberGroups
</part>
....more parts
</list>
every file 01.xml etc has one HTML-style table, like this:
<table class='wl'>
<tr class='header'>
<td><p>English</p></td>
<td><p>French</p></td>
</tr>
<tr>
<td><p>belly</p></td>
<td><p>ventre</p></td>
</tr>
<tr>
<td><p>leg</p></td>
<td><p>jambe</p>/td>
</tr>
... etc
</table>
I want to merge all the tables (3 in this example) into one, so I get a compete vocabulary.
So far I have this stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:result-document href="wl.xml">
<xsl:text disable-output-escaping="yes">
<!DOCTYPE html>
</xsl:text>
<html xmlns:epub="http://www.idpf.org/2007/ops" lang="nl" xml:lang="nl">
<head>
<title>
<xsl:value-of select="./title"/>
</title>
<xsl:apply-templates select="css"/>
</head>
<body>
<table>
<xsl:apply-templates select="//numberGroup[1]/entry">
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="entry">
<xsl:apply-templates select="document(file)//table[#class='wl']/tr[not(contains(#class, 'header'))]"/>
</xsl:template>
<xsl:template match="tr">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
which merges as desired, except for the sorting.
How can I sort the generated table alphabetically, on the first column?
Replace
<xsl:apply-templates select="//numberGroup[1]/entry">
</xsl:apply-templates>
with
<xsl:apply-templates select="document(//numberGroup[1]/entry/file)//table[#class='wl']/tr[not(contains(#class, 'header'))]">
<xsl:sort select="td[1]" data-type="text"/>
</xsl:apply-templates>
then you can drop the template for entry elements.

Xpath Query Help. Selecting data from multiple paths as a single data set

I have an xml structure like the following :
<doc>
<line void="false">
<lineNumber>1</lineNumber>
<info1>ddddd</info1>
<info2>aaaaa</info2>
</line>
<line void="true">
<lineNumber>2</lineNumber>
<voidLineNumber>1</voidLineNumber>
<voidValue>2.00</voidValue>
</line>
</doc>
I need one single set of data. I would like to select all the lines where void = false as well as the voidLineNumber and voidValue data from the line where void = true and the voidLineNumber = lineNumber from the original line.
Is this possible? Any help would be appreciated. Thanks
As Michael Kay noted, XPath itself can only be used to select nodes, not to transform them. You can do what you want with XSLT:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes" />
<xsl:template match="doc">
<xsl:apply-templates select="line" />
</xsl:template>
<xsl:template match="line">
<xsl:variable name="voidvalue"><xsl:value-of select="#void" /></xsl:variable>
<xsl:if test="$voidvalue='false'">
<xsl:copy>
<xsl:copy-of select="#*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:if test="name(.)='lineNumber'">
<xsl:value-of select="."/>
</xsl:if>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Extract image from CDATA-xml rss file into xslt

I need show with xslt information about an xml RSS feed.
The xml source is:
<description><![CDATA[<p>
<img style="margin: 10px;
float: left;" alt="Nuevo modelo general de negocio"
src="http://mysite.es/images/figure1.jpg" width="196" height="147" />
La compañía apuesta por un marcado giro en el modelo]]>
</description>
I´m using:
<xsl:value-of select="description" disable-output-escaping="yes"/>
But the rendering is not good because I need show a resize image, with size, for example 70x70.
I´ve tried with this but its wrong:
<xsl:value-of select="replace("description","images/","images/resized/images/")"
disable-output-escaping="yes"/>
The perfect solution for me would be to extract separated, both the src property and the text from the tag.
Regards,
María
If your xml always is like your example then you should be able to use something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<div>
<xsl:apply-templates select="rss/channel"/>
</div>
</xsl:template>
<xsl:template match="rss/channel">
<ul>
<xsl:apply-templates select="item"/>
</ul>
</xsl:template>
<xsl:template match="item">
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_title" select="substring-after(description, '/>')"/>
<xsl:variable name="item_image" select="substring-before(substring-after(description, 'src="'), '"')" />
<li>
<a href="{$item_link}">
<img alt="" src="{$item_image}" width="70" height="70" />
<xsl:value-of select="$item_title"/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>

Resources