[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Identifying unique attribute values in nested sibl
Hi Brandon,
First, I am saying absolutely nothing negative here about Ken's version -- he has been generous and most helpful for a considerable time now. Thanks, Ken. That said, what strikes me about your implementation is that you have structured it in an idiom I find quite familiar. What I see in your code are polymorphic functions calling upon the data rather than the code to do the messaging. Had I a far better command of XPath and were I more sensitive to power of XSLT, I suspect I might produce something similar your implementation. I find its polymorphic task resolution extremely satisfying. I think you are aware that my native coding language is C++. So far, I have been unsuccessful in leveraging my hard-earned C++ skill set to advantage with respect to XSLT and XPath. Your essay has given me a leg up. Thanks, Mark -----Original Message----- From: Brandon Ibach Sent: Wednesday, October 05, 2011 1:15 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Identifying unique attribute values in nested sibling elements To go a bit beyond Ken's suggestions, here's a very non-C++ style of approach, relying on the data to drive the processing, which XSLT supports very well. This assumes that you only have a single Value element in each Stamp. Your code seemed to indicate that this was the case and your use of <xsl:for-each> seemed to be mostly for purposes of shifting your context, but if there's a chance you might have more than one Value, that would make for some strange results, so it's something to look out for, if you don't have a schema to enforce such rules on your input. Hopefully, this isn't too hard to follow. I have a weakness for C-cubed code (concise, clever and, all too often, a bit cryptic). Besides the more content-driven style, the other main feature here is the simplification allowed by the fact that in all cases, your code was generating an <a class="button">, so you may as well only generate it once (the "DRY" rule works in any sort of programming, after all, regardless of the language used). <xsl:function name="cps:report"> <xsl:param name="Stamp"/> <xsl:variable name="file"> <xsl:apply-templates select="$Stamp/Value" mode="cps:href"/> </xsl:variable> <a class="button" href="../aval/{$file}.htm"> <xsl:apply-templates select="$Stamp/Value" mode="cps:text"/> </a> </xsl:function> <xsl:template match="Value[@l-value]" mode="cps:href"> <xsl:value-of select="lower-case(@l-value)"/> </xsl:template> <xsl:template match="Value[not(@l-value)]" mode="cps:href"> <xsl:value-of select="concat((@kc-value, 0)[1], '-')"/> <xsl:value-of select="(@h-value, 0)[1]"/> </xsl:template> <xsl:template match="Value[@l-value]" mode="cps:text"> <xsl:value-of select="@l-value"/> </xsl:template> <xsl:template match="Value[not(@l-value)]" mode="cps:text"> <xsl:variable name="kc" select="@kc-value[. ne '0']"/> <xsl:variable name="h" select="@h-value[. ne '0']"/> <xsl:value-of select="concat($kc, '.'[$kc][$h], $h)"/> <xsl:value-of select="if ($kc) then 'Kc' else 'h'"/> </xsl:template> -Brandon :) On Tue, Oct 4, 2011 at 10:23 AM, Mark <mark@xxxxxxxxxxxx> wrote: Hi Ken,</xsl:text> <xsl:text/></a> </xsl:when> <xsl:otherwise> <a class="button" href="../aval/{concat(., '-', $h)}.htm"> <xsl:value-of select="$h"/> <xsl:text>h</xsl:text> </a> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:when> </a> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:function>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|