Reputation: 5666
I'm using XSLT in my .NET (C#) project.
I want to know if it is possible to check inside XSLT template if an extension object was defined in (added to) XsltArgumentList
.
XSLT namespace declaration
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:info="urn:info">
C# Code
public string Render(XElement xml, IInfo info) {
XsltArgumentList arguments = new XsltArgumentList();
if(info != null)
arguments.AddExtensionObject("urn:info", info);
var writterSettings = GetWritterSettings(); //omitted details just for simplicity
var xslt = CreateXslCompiledTransform(); //omitted details just for simplicity
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb, writerSettings))
{
using (var itemReader = xml.CreateReader())
{
xslt.Transform(itemReader, xsltArguments, writer);
}
}
return sb.ToString();
}
Inside the XSLT template I want to do something with extension object when it is not null and something else when it is null. Is there some special tag or syntax for XSLT to accomplish this or it is not possible at all?
Upvotes: 3
Views: 691
Reputation: 122364
XSLT provides functions element-available()
and function-available()
for checking whether or not a particular extension element/function is available, so try something like
<xsl:choose>
<xsl:when test="function-available('info:myFunction')">
myFunction is available
</xsl:when>
<xsl:otherwise>
myFunction is not available
</xsl:otherwise>
</xsl:choose>
Upvotes: 3
Reputation: 5
I would suggest adding an additional parameter in your ArgumentList to denote whether it is null or not.
You could try the not() operator
Upvotes: 1