XSL Display error based on error code - xslt

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]" />

Related

Unable to get the value of 'xml:lang' attribute

<xoe:documents xmlns:xoe="http://xxxxxx" count="1">
<xocs:doc xmlns:xocs="xxxxxx" xmlns:xsi="yyyyyyy" xsi:schemaLocation="zzzzzz">
<xocs:meta>...</xocs:meta>
<xocs:serial-item>
<!-- this line -->
<article xmlns:sa="www.google.hgy" xmlns="http://www.xyzq1.org/xml/ja/dtd" version="5.4" xml:lang="pl" docsubtype="rev">
<article-info>
</article-info>
</article>
</xocs:serial-item>
</xocs:doc>
</xoe:documents>
I am unable to get the value of 'xml:lang' attribute. Even thought I tried with the below xpath
<xsl:variable name="rootPath" select="/xoe:documents/xocs:doc/xocs:serial-item"/>
<xsl:variable name="lang" select="$rootPath/ja:article[#xml:lang]"/>
or
<xsl:variable name="lang" select="$rootPath/ja:article/#xml:lang"/>
here ja is already defined in my xslt code
xmlns:ja="http://www.xyzq1.org/xml/ja/dtd"
Can some one please help?
First, you need to declare these:
xmlns:xoe="http://xxxxxx"
xmlns:xocs="xxxxxx"
xmlns:ya="www.yahoo.mkt"
Then you can get the value of the xml:lang attribute using:
<xsl:value-of select="/xoe:documents/xocs:doc/xocs:serial-item/ya:article/#xml:lang"/>
Note that the URIs in your stylesheet namespace declarations must be the same URIs that appear in your source XML. The prefixes can be anything you like.

Saxon: XSLT image processing: cannot convert from xs:string to byte

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)))" />

Getting the value of an attribute in an XML document using XSL

I'm trying to get the value of iWantToGetThis.jpg and put it into an <img> during my XSL transformation. This is how my xml is structures:
<article>
<info>
<mediaobject>
<imageobject>
<imagedata fileref='iWantToGetThis.jpg'>
Here's what I've come up with for the XSL:
<xsl:template name="user.header.content">
<xsl:stylesheet xmlns:d='http://docbook.org/ns/docbook'>
<img><xsl:attribute name="src">../icons/<xsl:value-of select='ancestor-or-self::d:article/info/mediaobject/imageobject/imagedata/#fileref' /></xsl:attribute></img>
</xsl:stylesheet>
</xsl:template>
The image is being added to the output, but the src attribute is set to "../icons/", so I'm assuming it's not finding the fileref attribute in the XML. This looks perfectly valid to me, so I'm not sure what I'm missing.
I am not sure how you can get anything back at all, because that does not look like a valid XSLT document (I would expect the error "Keyword xsl:stylesheet may not contain img.").
However, it may be you are just showing a fragment of the code. If this is the case, your issue may be that you have only specified the namespace for the article element, when you really need to specify it for all elements in your xpath. Try this
<xsl:value-of
select="ancestor-or-self::d:article/d:info/d:mediaobject/d:imageobject/d:imagedata/#fileref"/>
Another possible problem may be because you are using the 'ancestor-or-self' xpath axis to find the attribute. This would only work if your current context was already on the article element, or one of its descendants.
As a side note, you can simplify the code by making use of Attribute Value Templates here
<img src="../icons/{ancestor-or-self::d:article/d:info/d:mediaobject/d:imageobject/d:imagedata/#fileref}" />

How do I access the querystring in an Umbraco template?

I'm trying to get hold of the querystring directly from the template in Umbraco, but can't seem to figure it out..
For example:
/mypage.aspx?p=bek
I can do it with <%=HttpContext.Current.Request["p"]%>, but I want it in a field...
Something like this:
Any ideas?
Ok, so I fixed it.
Found this:
http://forum.umbraco.org/yaf_postst6663_Get-querystring-in-template.aspx
If anyone else is interested, you do the following..
Create a xslt file with the name "QueryStringExtractor" and paste the below code where it belongs.
<xsl:param name="currentPage"/>
<xsl:variable name="yourvalue" select="//macro/myparam" />
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:value-of select="$yourvalue" />
</xsl:template>
Save and update the Umbraco page and you'll see a macro under "Macros" with the same namne.
In the macro you add the parameter "myparam" (I put it as text). Save!
Then in your template just past the following code and you're good to go!
<ul>
<umbraco:Macro Alias="QueryStringExtractor" myparam="[#p]" runat="server"></umbraco:Macro>
</ul>
So now when you enter the querystring "?p=something" you'll get "something" written on the page.
Notice that you can pass any "p" to the macro.
Hope this helps someone else!

Local XML namespace definition not working as I expected

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'/>