Display image from a shared folder using XSL - xslt

I'm trying to display an image from a shared folder but I'm getting error
INVALID XPATH EXPRESSION or INVALID QUALIFIED NAME
This is the code, here fyi, 160.115 is my machine IP having shared folder "SHARE" which is open to all to read and write.
` <xsl:template match="element">
<img>
<xsl:attribute name="src">
<xsl:value-of select="file:\\172.16.160.115\share\german_shepherd_icon.jpg"/>
</ xsl:attribute>
</img>
</xsl:template>

The select attribute of value-of is an XPath expression, so if you want the value to be a literal string then you'd need to wrap it in quotes (select="'literal value'"). But far simpler would be just to use a literal attribute (note you need forward slashes rather than backward ones as it's a URI):
<img src="file://172.16.160.115/share/german_shepherd_icon.jpg"/>

Related

How to use a variable value

The variable behaviour here does not work as expected.
I have a variable named fonttag with a value that is an HTML line with both start and end tags and a divider.
<xsl:variable name="fonttag">
<font face="ANGSANA NEW" size="12">|</font>
</xsl:variable>
When I try to use it, to get part of the string back, I get an empty string:
<xsl:value-of select="substring-before($fonttag ,'|')"/>
Where I expected the substring :
<font face="ANGSANA NEW" size="12">
Similarly the
<xsl:value-of select="$fonttag"/>
returns nothing, although
<xsl:copy-of select="$fonttag"/>
return the whole string. Is there another way to achieve the expected result ?
A derived-question: Is it possible to nest xsl select tags like this (cannot get it to work either)
<xsl:copy-of select="substring-before( <xsl:copy-of select="$fonttag"/>,'|')"/>
?
thanks
I am afraid you misunderstand how XSLT works. Your variable does not contain the string "<font face="ANGSANA NEW" size="12">|</font>". It contains the element font, with two attributes, and the string value of "|". The xsl:value-of instruction, as well as any string function such as substring(), only address the string value of the given expression.

Building custom hyperlink

This is driving me slightly potty!
I have a datasheet webpart and I would like to add a hyperlink to one of the columns to open the item in the popout/modal fashion.
So far I have:
<a><xsl:attribute name="href">
<xsl:value-of select="concat('https://mysite/_layouts/listform.aspx?PageType=4&ListId={listiD}&ID=',#ID,'&ContentTypeID=0x0100B0D8940B0260E54DA1649533F29D58D7')"/>
</xsl:attribute>
<xsl:value-of select="#Title" /></a></td>
(I have edited the above code to remove identifying features)
The error that I am getting is "This Web Part does not have a valid XSLT stylesheet. Error: A semi colon character was expected"
I really don't know what to do to fix this!
Thanks in advance,
MW
This is because of the use of the ampersand & in your statement. It needs to be escaped as & to stop XSTL trying to treat the following characters as an entity.
Try this instead:
<xsl:value-of select="concat('https://mysite/_layouts/listform.aspx?PageType=4&ListId={listiD}&ID=',#ID,'&ContentTypeID=0x0100B0D8940B0260E54DA1649533F29D58D7')"/>

How to strip Unicode soft hyphen from PDF bookmarks generated using XSL-FO

I'm converting DITA maps to PDF using the DITA Open Toolkit 1.7 and RenderX XEP. In the DITA topics, product names are inserted using conrefs. One of my product names is quite long. It caused layout problems when used within tables. Therefore I inserted a soft hyphen into the phrase that is reused via conref:
<ph id="PD_FineReader2Comp">DOXiS4 FineReader2­Components</ph>
This works nicely in the generated pages, but creates a problem in the bookmarks where a symbol is displayed in place of the soft hyphen.
Obviously, this is an encoding problem. It seems that UTF-8 characters are properly handled in PDF content, but not in PDF bookmarks where, according to the following sources, some PDF-16 characters can be used (but I did not understand which ones).
http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf
http://www.setasign.de/support/tips-and-tricks/use-unicode-in-string-values/
The DITA Open Toolkit seems to create bookmarks from topic titles using this code fragment:
<fo:bookmark>
<xsl:attribute name="internal-destination">
<xsl:call-template name="generate-toc-id"/>
</xsl:attribute>
<xsl:if test="$bookmarkStyle!='EXPANDED'">
<xsl:attribute name="starting-state">hide</xsl:attribute>
</xsl:if>
<fo:bookmark-title>
<xsl:value-of select="normalize-space($topicTitle)"/>
</fo:bookmark-title>
<xsl:apply-templates mode="bookmark"/>
</fo:bookmark>
The XSL stylesheet has version 2.0.
I would like to create an override that removes the offending character. How can I do this?
Is it possible to properly resolve the encoding problem? (Probably not possible).
Are there any XSL functions or attributes which remove whitespace other than space, tab, linefeed, and carriage return?
Or do I need special handling for the soft hyphen?
Small refinement: If you are using XSLT2, will be more efficient than in this context. In XSLT2 you should always prefer xsl:sequence over xsl:value-of
The simple way to do this is to use the translate() function, which can be used to replace certain characters with other characters, or with nothing. It looks like this is the line that outputs the value you want to fix up:
<xsl:value-of select="normalize-space($topicTitle)"/>
So you could simply modify this to:
<xsl:value-of select="translate(normalize-space($topicTitle), '­', '')"/>
to remove all the soft hyphens. If you would like to replace them with spaces or ordinary hyphens, you could do either of the following, respectively:
<xsl:value-of select="translate(normalize-space($topicTitle), '­', ' ')"/>
<xsl:value-of select="translate(normalize-space($topicTitle), '­', '-')"/>

Concatenate with escaped chars in xslt?

I'm writing xslt code which concatenates some string:
<xsl:attribute name='src'>
<xsl:value-of select="concat('url(&apos;', $imgSrc, '&apos;)')" />
</xsl:attribute>
For some reason I can't use it, I keep getting this error:
Unknown function - Name and number of arguments do not match any function signature in the static context - 'http://www.w3.org/2005/xpath-functions:concat'
while evaluating the expression:
select="concat('url(&apos;', $imgSrc, '&apos;)')"
Any idea?
thx
====================
EDIT
I'm trying to get:
url('some_path')
Was having trouble with the apostrophes, but now it just doesn't work.
The &apos; references are resolved by the XML parser that parses your XSLT. Your XSLT processor never sees them. What your XSLT processor sees is:
concat('url('', $imgSrc, '')')
Which is not valid because the commas don't end up in the right place to separate the arguments. However, this might work for you, depending on the serializer your XSLT processor uses:
concat("url('", $imgSrc, "')")
This surrounds the arguments in double-quotes, so that your single-quotes do not conflict. The XSLT processor should see this:
concat("url('", $imgSrc, "')")
Another option is to define a variable:
<xsl:variable name="apos" select='"&apos;"'/>
Which can be used like this:
concat('url(', $apos, $imgSrc, $apos, ')')
More here:
When you apply an XSLT stylesheet to a
document, if entities are declared and
referenced in that document, your XSLT
processor won't even know about them.
An XSLT processor leaves the job of
parsing the input document (reading it
and figuring out what's what) to an
XML parser; that's why the
installation of some XSLT processors
requires you to identify the XML
parser you want them to use. (Others
include an XML parser as part of their
installation.) An important part of an
XML parser's job is to resolve all
entity references, so that if the
input document's DTD declares a cpdate
entity as having the value "2001" and
the document has the line "copyright
&cpdate; all rights reserved", the XML
parser will pass along the text node
"copyright 2001 all rights reserved"
to put on the XSLT source tree.
From http://www.w3.org/TR/xpath/#NT-Literal
[29] Literal ::= '"' [^"]* '"' | "'" [^']* "'"
Meaning that an XPath literal string value can't have the delimiter as also part of the content.
For this you should use the host language. In XSLT:
<xsl:variable name="$vPrefix">url('</xsl:variable>
<xsl:variable name="$vSufix">')</xsl:variable>
<xsl:attribute name="src">
<xsl:value-of select="concat($vPrefix, $imgSrc, $vSufix)" />
</xsl:attribute>
Or more proper:
<xsl:attribute name="src">
<xsl:text>url('</xsl:text>
<xsl:value-of select="$imgSrc"/>
<xsl:text>')</xsl:text>
</xsl:attribute>

xsl strange behaviour using variables

I've stored a file's tree into $onto
<xsl:variable name="onto" select="document('file.xml')"/>
In some places I can use this variable as espected:
<xsl:copy-of select="$onto/rdf:RDF"/>
But I'm having trouble in other places, strange chars are written on output:
<xsl:element name="autor">
<xsl:attribute name="rdf:resource">
<xsl:text>#</xsl:text> <xsl:value-of select="$onto"/>
</xsl:attribute>
</xsl:element>
This is the beginig of the output I've got:
<autor rdf:resource="#
What I'm missing? What's wrong?
If that's to much for an attribute, what can I do?
Thank you
When <xsl:value-of> is applied to a tree fragment, it takes the text content of that tree. In your case, it looks like your XML file doesn't contain any text (other than whitespace) which isn't in an attribute value. I suspect that you mean to select the value of a particular attribute node within the document, e.g.:
<xsl:value-of select="$onto//foo/#bar"/>
(Without knowing the structure of your XML and what you're trying to select, I don't know what the real path would be.)