Anyone here know xsl?
A little.
Got a question about technology? Ask it here. Discussion of hardware, software, TiVos, multi-region DVDs, Windows, Macs, LINUX, hand-helds, iPods, anything tech related. Better than any helpdesk!
Anyone here know xsl?
A little.
I've used and written a little simple xsl, but it's not something I work with very often at all. I might be able to help if it's a pretty simple question.
I don't know if I can even explain this correcly....
OK, say we have the xsl:
<xsl:template match="/"> <xsl:for-each select="employees/employee[@g=0]"> <option> <xsl:attribute name="value"><xsl:value-of select="@i"/></xsl:attribute> <xsl:value-of select="@n"/> - <xsl:value-of select="status/@s" /> </option> </xsl:for-each> </xsl:template>
I want the stuff in the for-each loop to only happen if the
xsl:value-of select="status/@s"
actually matches something.
There's more stuff going on, but hopefully this is enough info....
eta: the <option> stuff is only there because this is returning html that's used in a drop-down box.
Easy-peasy.
<xsl:template match="/"> <xsl:for-each select="employees/employee[@g=0]"> <xsl:if test="status/@s"> <option> <xsl:attribute name="value"><xsl:value-of select="@i"/> <xsl:value-of select="@n"/> - <xsl:value-of select="status/@s" /> </option> </xsl:if> </xsl:for-each> </xsl:template>
Although if it's more complicated than that, you'll probably end up having to use an t xsl:choose instead of an t xsl:if
.
Thanks - I'll give that a try.
That was the direction I was going in, but I didn't know about the
<xsl:if test=
stuff....
OK, that's not working, so I'll have to explain the (more) confusing stuff.
The thing is, the
xsl:value-of select="status/@s"
would normally match to multiple rows, except that there's a criteria/filter put on the xsl by the javascript that applies the xsl on the xml.
That looks like this:
xslStyle.loadXML(xslEmployeeComboboxDept.XMLDocument.xml); selectField = xslStyle.selectSingleNode("//xsl:value-of[@select='status/@s']/@select"); selectField.value = "status[@pp=" + varPayPeriod + "]/@s" strTemp = xmlMaster.transformNode(xslStyle);
xslEmployeeComboboxDept is the stylesheet where I excerpted the above xsl.
I don't fully understand how this works, but it normally limits
xsl:value-of select="status/@s"
to a single match. Sometimes there are no matches, which is what i want to exclude....
That's very weird, tommyrot.
Edit: Basically, what the original programmer is doing is modifying the stylesheet on the fly, so that the stylesheet that is executed will be different than what the code you see.
Very kludgy.
Tommyrot, what I would do is get rid of the lines:
selectField = xslStyle.selectSingleNode("...");
selectField.value = "status[@pp=" + varPayPeriod + "]/@s"
replace it with:
xslStyle.addParameter("varPayPeriod", varPayPeriod);
add a
<xslt:param name="varPayPeriod"/>
to the beginning of your .xsl file, and change the
<xsl:value-of select="status/@s" />
to
<xsl:value-of select="status[@pp=$varPayPeriod]/@s" />
and use
<xsl:if test="status[@pp=$varPayPeriod]/@s" />
You have my permission to go and beat the original programmer with a stick.
(I might not have the syntax correct, you might have to use @pp='$varPayPeriod' with single quotes)
Thanks, Tom.
what the original programmer is doing is modifying the stylesheet on the fly, so that the stylesheet that is executed will be different than what the code you see.
Very kludgy.
Heh. That's probably why I couldn't find anything like it in my "Beginning XML" book. I think that book does have the technique of passing a parameter to xsl like you show.
I've got a few other things to do, but I'll try your code out soon.
A city in Oklahoma was threatening the CentOS Linux distribution because the default Apache test page was showing up on their website.
OMG. I've had customers like that. Unbelievable. The distro guy was unbelievably patient and the OK guy was an asshat not to apologize.