The following code:
<xsl:message>[threfUrl] <xsl:value-of select="$threfUrl" /></xsl:message>
<xsl:variable name="actualHeight" select="itext:getPlainHeight(itext:getInstance($threfUrl))" />
throws this error:
[xslt] [threfUrl] file:/data/dtemple/share/dita_share/png_debug/screenshot_example.png
[xslt] /tools/dita_ot/1.6/plugins/com.altera.pdf/cfg/fo/xsl/altera_commons.xsl:1124: Fatal Error! Cannot convert from xs:string to byte
The PNG file exists and is readable. Using Saxon 9. Namespace: itext="java:com.itextpdf.text.Image"
Any clues as to what is wrong (the error message is not helpful) or how to fix?
Is the "file:/" syntax correct?
Assuming you are using http://api.itextpdf.com/itext/com/itextpdf/text/Image.html#Image%28java.net.URL%29 try select="itext:getPlainHeight(itext:new($threfUrl))". If that does not work then construct the URL explicitly, as in
<xsl:variable name="actualHeight" xmlns:url="java:java.net.URL" select="itext:getPlainHeight(itext:new(url:new($threfUrl)))" />
The documentation I cited says
Constructor Detail
Image
public Image(URL url)
Constructs an Image -object, using an url .
Parameters:
url - the URL where the image can be found.
so that constructor is public.
Maybe there are different versions of that API, I am not sure why you get an error. Another try might be your original attempt, but passing in a URL, so
<xsl:variable name="actualHeight" xmlns:url="java:java.net.URL" select="itext:getPlainHeight(itext:getInstance(url:new($threfUrl)))" />
Related
This may be somewhat naive but I am quite struck on the issue
There is a specific <result> element in DataPower and when calling through xslt we have somewhat following format(which I discovered in some forums)--
<results mode="require-all" multiple-outputs="true" transactional="true" retry-interval="100" asynchronous="false">
<url input="var://the_request_SOAP_Format"asynchronous="true">https://XXXXXXX</url>
now in this (url input) is the request which needs to be send and (https://XXXXXXX) is the specified backend where it needs to be sent
Now I have some authentication headers(httpHeaders) also which I need to send without which I will get Authorization error
<xsl:variable name="httpHeaders">
<header name="Content-Type">application/json</header>
<header name="Authorization">
<xsl:value-of select="concat('Bearer ',$some_sessionID)"/>
</header>
</xsl:variable>
Is this possible to add these 'httpHeaders' in the result mode element/Tab property
Thanks
I am not exactly sure what you are trying to achieve but adding http headers for the response (backside) you do with:
<dp:set-http-response-header name="'HeaderName'" value="$httpHeaders"/>
or
<dp:set-http-request-header name="'HeaderName'" value="$httpHeaders"/>
The <results> is the collection of data that the Processing Policy will output as Payload for the Request/Response and won't contain headers. You shouldn't try to alter the <results> object!
The "results-doc" method of calling backends is quite powerful, but I'm not sure from your question if you fully understand it. The url/#input attribute needs to be a DataPower context:
<url input="var://context/mycontext" ...
To associate headers with that context, you should do something like this for each header you need:
<dp:set-variable
name="'var://context/mycontext/_extension/header/Content-Type'"
value="'application/json'"/>
(This would be done in your XSLT code, separate from creating the "results" document, but before you use a Results Action to execute.)
I have an XML document that contains multiple pre-defined error message that has a structure similar to this
<main>
<error>
<code1>message</code1>
<code2>message</code2>
</error>
<main>
Certain operations can return errors and the error code is added in the request so that the error is displayed on the page:
_request.setAttribute("errorCode", errorCode);
In the XSL document I have a structure like this:
<xsl:if test="root/request/error">
<div class="grid_16 errors">
<xsl:value-of select="concat('/root/main/error/', root/request/errorCode)"/>
</div>
</xsl:if>
The error code is placed in the request like this:
_request.setAttribute("error", "true");
_request.setAttribute("errorCode", errorCode.get());
However, the error is not displayed, but instead the result of the concatenation (the string /root/main/error/code1). If I put, for example, one error code like this, it works: <xsl:value-of select="/root/main/error/code1"/>
Is there a way to properly display the error by providing the just the code?
This solves the problem:
<xsl:value-of select="/root/main/error/*[name()=/root/request/errorCode]" />
I am using xslt 1.0.
I want to import A.xsl into B.xsl.
I am unable to use relative paths in href attribute of xsl:import. for ex. path is c:/test/testdata/xsl/file/A.xsl
I tired following code
<xsl:variable name="filePath" select="concat(Systemprop:getProperty('docRootPath'),'/xsl/file/A.xsl')" />
and
<xsl:import href="{concat(Systemprop:getProperty('docRootPath'),'/xsl/file/A.xsl')}">
where docrootPath = c:/test/testdata
but its is giving error : Element type "xsl:variable" must be followed by either attribute specifications, ">" or "/>".
but its giving me :Had IO Exception with stylesheet file. Please suggest .
See the spec, http://www.w3.org/TR/xslt#section-Combining-Stylesheets, it defines the syntax for include and import as
<!-- Category: top-level-element -->
<xsl:include
href = uri-reference />
<xsl:import
href = uri-reference />
So the href attribute value needs to be a URI reference, neither an expression nor an attribute value template is allowed there. So putting in an XPath expression like concat(...) is not possible, is not supported.
A relative URI reference can be used of course, but you would need to make sure a base URI is defined properly, for instance doing <xsl:import xml:base="file:///C:/test/testdata/" href="file.xml"/>. That is however also only a static value to be defined during stylesheet authoring.
If I want to load a document into a variable, I can use
<xsl:variable name="var1" select="document('http://www.mySite.com/file1.xml')" />
=> works, I can use -
<xsl:value-of select="$var1//myNodeName"/>
but now I need to use a URL with parameter.
and the following tests do not work -
<xsl:variable name="var2" select="document('http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2')" />
=> does not work - EntityRef: expecting ';'
<xsl:variable name="var2" select="document('http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2')" />
=> does not work - warn for wrong URL -
http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2:1:
why does it add :1: ???
My Question:
How do I replace the & entity to make the document() function work?
Update:
according to -
http://our.umbraco.org/forum/developers/xslt/5421-Ampersand-in-XSLT
the solution is to store the URL as a variable, then output it disablig output escaping.
e.g.
<xsl:variable name="test" select="http://www.mysite.com/mypage.aspx?param1=1¶m2=2" />
<xsl:value-of select="$test" disable-output-escaping="yes" />
but, how can I apply this solution with document() parameter?
Update 2:
I parse it using PHP -
<?php
Header('Content-type: text/xml');
// http://php.net/manual/en/xsltprocessor.transformtoxml.php
$xml = new DOMDocument;
$xml->load('http://www.mySite.com/devices.xml');
$xsl = new DOMDocument;
$xsl->load('mergedocs.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
?>
The error I get [note the amp within the URL]:
XML Parsing Error: junk after document element
Location: http://mySite/myPhpFile.php
Line Number 2, Column 1:<b>Warning</b>: XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]:
http://siteIp/cgi-bin/getfile.cgi?p1=v1&p2=v2:1: parser error : Document is empty
in <b>/home/.../myPhpFile.php</b> on line <b>16</b><br />
Encoding the & as & is the correct approach, the URL retrieved by the processor will be the correct one with val1¶m2. I suspect the :1: isn't part of the URL but rather part of the warning message i.e. problem at ::
I'm processing an XMI document exported from ArgoUML. It has elements of the form
<UML:DataType href='http://argouml.org/profiles/uml14/default-uml14.xmi#-84-17--56-5-43645a83:11466542d86:-8000:000000000000087C'/>
which points to an item of the form
<UML:DataType xmi.id="-84-17--56-5-43645a83:11466542d86:-8000:000000000000087C"
name="Integer"
isSpecification="false"
isRoot="false"
isLeaf="false"
isAbstract="false"/>
I've already declared xmlns:UML="org.omg.xmi.namespace.UML" at the top of the xslt file. I think I should be using something like :
<xsl:variable name="typeref" select="#href"/>
<xsl:variable name="ns" select='substring-before($typeref, "#")'/>
<xsl:variable name="identifier" select='substring-after($typeref, "#")'/>
<xsl:value-of xmlns:UML="$ns"
select='//UML:DataType[#xmi.id="$identifier"]/#name'/>
to deduce that my UML attributes type is Integer but this gives me
SystemId Unknown; Line #136; Column #94; A location step was expected following the '/' or '//' token.
If I change the xmlns to AAA then I get no error but an empty tag. I'm using Xalan2 on Debian squeeze. What am I missing?
Don't mind me. Just making the classic mistake of conflating namespaces and URIs. What I really needed was <xsl:value-of select='document($ns)//UML:DataType[#xmi.id=$identifier]/#name'/>