Developer forum

Forum » Development » TagExists in XSLT template

TagExists in XSLT template


Reply

Hi there,

Is it possible to check if a certain tag is in use in an XSLT template? With loops you can use the availableloops approach, but is there tag equivalent?

BR.
Lars


Replies

 
Reply
Hi,

There is no tag, but you can use some xslt functions, for example

<xsl:if test=" MyTag != '' ">
  // do something
</xsl:if>

<xsl:if test="string-length(MyTag) > 0">
  // do something
</xsl:if>

Best Regard,
Nuno
 
Reply
Hi Nuno,

I need it the other way around. I want my C# code to check whether a certain tag is used in the XSLT template.

But thanks anyway;-)

BR.
Lars
 
Nicolai Høeg Pedersen
Reply
From code use tagexist or loopexist.

Loopexist with xslt requires the "available loops" approach in some situations, but with normal "template tags" like <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>, just use tagexist.
 
Reply

I tried that to begin with, but in an XSLT template it returns true every time. At least that's what I've experienced. Just to make sure, I tried the following:

Base.wa(Template.TagExists("Yadayada"));

The result was an alert box with the text True:

<script>alert('True');</script><br />

BR.
Lars

 
Reply
Btw. LoopExists works perfectly for this, but TagExists would be much prettier, since it's just a tag and not a loop:)

/Lars
 
Nicolai Høeg Pedersen
Reply
Well

Just checked out the code, and there is an issue. I've bugged it, so a fix is coming up.

Untill then do something like this:

If (t.IsXsltTemplate AndAlso t.Html.Contains("@MenuText")) OrElse t.TagExists("MenuText") Then
 t.SetTag("MenuText", LongRunningThing())
End If

 

You must be logged in to post in the forum