Umbraco NiceUrl ToLower - xslt

I'm trying to change the URL to lower in my href tag, here is my code:
<a href="{$url}{umbraco.library:NiceUrl(#id)}/{$AppendedID}/">
I've tried using Exslt.ExsltStrings:lowercase(node-set) with no joy as this throws an error. Does anyone have any suggestions?

The following expression should work:
Exslt.ExsltStrings:lowercase(concat($url, umbraco.library:NiceUrl(#id), '/', $AppendedID, '/'))
Testing with the following piece of code ....
<xsl:for-each select="$currentPage">
<xsl:variable name="url" select="'http://www.EXAMPLE.com'" />
<xsl:variable name="AppendedID" select="123" />
<a href="{Exslt.ExsltStrings:lowercase(concat($url, umbraco.library:NiceUrl(#id), '/', $AppendedID, '/'))}">
<xsl:value-of select="#nodeName" />
</a>
</xsl:for-each>
.... the rendered HTML should be along the lines of ....
Some Page

I don't know direct way to solve this except using Exslt.ExsltStrings:lowercase(node-set)
but is this throw error when you use it with umbraco.library:NiceUrl then you may try to make the string lower and store it in temp variable then use this temp variable directly.

Related

URL Encoding in XSL in DataPower [duplicate]

I have a problem writing my XSL. I have a link with the following code:
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($myUrl,'&projectNumber=',$projectNumber)"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
LINK
</a>
So I need to pass a variable projectNumber to the end of myUrl. This works just fine and I get ...myUrl...&projectNumber=...projectNumber... in HTML.
The problem is, that the variable projectNumber sometimes has some characters which have to be escaped in the href of my link. I tried using the XSL function str:escape-uri() in many different ways, but still no success...
For example if myUrl is www.example.com/example.aspx?a=b and projectNumber is aaaūaaa
I get href like www.example.com/example.aspx?a=b&projectNumber=aaaūaaa, but I need to get www.example.com/example.aspx?a=b&projectNumber=aaa%C5%ABaaa. (%C5%AB is the way that 'ū' is escaped) Any suggestions? Thanks.
If you are using XSLT 1.0,
then refer this.
In case of XSLT 2.0, you may use this to solve the issue.
<xsl:value-of select="concat($myUrl,'&projectNumber=',encode-for-uri($projectNumber))"/>

xslt variable set based on condition

I would like to set an xsl variable based on a condition. The xsl below is not currently working for me. I've been able to make two different matchers (<xsl:template match="rule/condition" and <xsl:template match="condition/condition") which enables me to put the ;display:none on just condition/condition matches but that results in the template being duplicated except for the one part of ;display:none. Guess I'm under the impression that I should be able to dynamically set a variable based on a condition but maybe my impression is wrong?
<xsl:template match="condition">
<xsl:variable name="display">
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
</xsl:variable>
<div style="{$divIndent}{$display}">
<a href="javascript:void(0)" style="{$expandPosition}" onclick="expandContents(this)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<condition type="<xsl:value-of select="#type"/>"><br />
<xsl:apply-templates select="expression" />
<xsl:apply-templates select="condition" />
</condition>
</div>
</xsl:template>
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
This asks if the name of the parent is equal to the value of the child whose name is condition. You probably want to know if the name of the parent is the literal value "condition":
<xsl:if test='name(..)="condition"'>;display=none</xsl:if>
However, it might be more idiomatic to write:
<xsl:if test='parent::condition'>;display=none</xsl:if>
Note also that display:none is valid css, display=none prbably won't work.
Try below code by adding attribute style
<div><xsl:attribute name ="style"><xsl:if test='name(..)=condition'>display=none;</xsl:if></xsl:attribute></div>

How do I output html markup stored in a xsl:variable

I am trying to render markup stored in a variable but I am getting no joy. Reason its cached is because I am using this several times in the page
<xsl:variable name="imgHtml">
<figure>
<img src="{$img}" alt="" class="" />
<figcaption>
<p><xsl:value-of select="name" /></p>
Enlarge Image
</figcaption>
</figure>
</xsl:variable>
I then reference the variable using the value-of elment
<xsl:value-of select="$imgHtml" /> but for some reason, the HTML does not render. Don't be shy, I need the help. Thanks!
Use <xsl:copy-of select="$imgHtml"/>, value-of always creates a plain text node.
The other answers were not working for me, however this did:
<xsl:value-of select="$variable" disable-output-escaping="yes"/>

xsl transform: problem with Ampersand URL parameters

I'm having issues with transforming XSL with parameters in a URL. I'm at a point that I can't change the C# code anymore, only can make changes to xsl file.
C# code:
string xml = "<APPLDATA><APPID>1052391</APPID></APPLDATA>";
XmlDocument oXml = new XmlDocument();
oXml.LoadXml(xml);
XslTransform oXslTransform = new XslTransform();
oXslTransform.Load(#"C:\Projects\Win\ConsoleApps\XslTransformTest\S15033.xsl");
StringWriter oOutput = new StringWriter();
oXslTransform.Transform(oXml, null, oOutput)
XSL Code:
<body>
<xsl:variable name="app">
<xsl:value-of select="normalize-space(APPLDATA/APPID)" />
</xsl:variable>
<div id="homeImage" >
<xsl:attribute name="style">
background-image:url("https://server/image.gif?a=10&Id='<xsl:value-of disable-output-escaping="yes" select="$app" />'")
</xsl:attribute>
</div>
</body>
</html>
URL transformed:
https://server/image.gif?a=10&Id='1052391'
URL Expected:
https://server/image.gif?a=10&Id='1052391'
How do I fix this? The output (oOutput.ToString()) is being used in an email template so it's taking the URL transformed literally. When you click on this request (with the correct server name of course), the 403 (Access forbidden) error is being thrown.
The problem is not the ampersand but the single quotes around the id. If they have to be present they have to be url encoded.
So (assuming no quotes are needed around the id) this should work:
<body>
<xsl:variable name="app">
<xsl:value-of select="normalize-space(APPLDATA/APPID)" />
</xsl:variable>
<div id="homeImage" >
<xsl:attribute name="style">
<xsl:text disable-output-escaping="yes">background-image:url('https://server/image.gif?a=10&Id=</xsl:text>
<xsl:value-of disable-output-escaping="yes" select="$app" />
<xsl:text>')</xsl:text>
</xsl:attribute>
</div>
</body>
What you get is actually what you want. The ampersand must be escaped in HTML, no matter where it occurs. So this
<div
id="homeImage"
style="background-image:url("https://server/image.gif?a=10&Id='1052391'")"
></div>
acutally is valid HTML, while this
<div
id="homeImage"
style="background-image:url("https://server/image.gif?a=10&Id='1052391'")"
></div>
is not (check it in the validator). The error you receive must come from somewhere else.

How to generate link with XSLT

Hi i've made a php webservice that returns some xml which is transformed into html by an XML file i have . But i want to be able to click on each returned item to get more details about that item. <?php echo $itemname"?>
Recently i did the same thing but in PHP, ive tried to use this in XSLT but it doesn't work.
Use xsl:attribute:
<a>
<xsl:attribute name="href">item.php?id=<xsl:value-of select="ItemId" /></xsl:attribute>
<xsl:value-of select="ItemName" />
</a>
Alternatively, the shorter form:
<xsl:value-of select="ItemName" />
Should also work