[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: PARAMS and VARIABLES in XSL
mark bordelon wrote:
I need help with the following problem. Well, if you mean with "not true siblings" that you have missed the closing tag, you are out of luck: it is not XML. But you just made a copy n paste mistake, and each sound tag is an empty tag, here's your solution: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes" /> <xsl:template match="word"> <word soundtime="{preceding-sibling::sound[1]/@time}"> <xsl:value-of select="." /> </word> </xsl:template> <xsl:template match="text()" /> </xsl:stylesheet> The delete-template for text() is one way to get rid of the whitespace that would otherwise be output (but is not necessary with your input). To make this work, you must first make XML from your input. <?xml version="1.0" encoding="UTF-8"?> As a general rule: never start a match with "//". It is not necessary for any reason. Just 'clause/*' would do if you want to match all nodes that have a parent 'clause' (which is not what you want, I think). <xsl:param name="soundtime" /> Somehow this looks like trying to redefine a parameter. Which is not allowed, ever. Using 'local-name()' is redundant. If you want to test for a node that is there, just do: <xsl:if test="sound" >.... <xsl:if test="local-name() = 'word'"> same here <word sound = "{$soundtime}" > You may be falling in the trap of thinking as XSLT as a 'normal' language, where 'normal' is defined as "take variable X, assign it value Y, read out variable X, assign it another value Z, do something else... etc". Which is the Java, VB, C++ etc way of doing things. Not so in XSLT. Assignment of variables is not possible at all. Here you define the rules and the processor does the thinking for you. If you find yourself making many xsl:if and xsl:choose, you are probably missing something vital somewhere. A rule is defined like: <xsl:template match="somenode"> ... DO something IF this node is encountered in the source To select what set of nodes you want to process, you use xsl:apply-templates + select.
|
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
|