Subject: RE: Another newbie question (from Sanjay Saxena) From: Kay Michael <Michael.Kay@xxxxxxx> Date: Wed, 8 Dec 1999 12:17:12 -0000 |
Your problem is to find an element whose name is not known until execution time. The only way to do this is to write an expression that matches all elements, and use name() or local-name() in the predicate to select more precisely. So you need something like <xsl:for-each select="CONTAINER"> <xsl:variable name="pre" select="string(PRE_HTML)" <xsl:copy-of select="//*[name()=$pre]"/> <!-- Do some more things here --> <xsl:variable name="post" select="string(POST_HTML)" <xsl:copy-of select="//*[name()=$pre]"/> </xsl:for-each> This will not be efficient, you could probably improve the performance using keys. Note that the <xsl:copy-of> element must be empty. Mike Kay -----Original Message----- From: Sanjay Saxena [mailto:ssaxena@xxxxxxxxxxxxx] Sent: 08 December 1999 01:43 To: xsl-list@xxxxxxxxxxxxxxxx Subject: Another newbie question Hi, I am a newbie so please bear with me. In my XML, I have meta-data which references data. For example, my XML looks as shown: <CONTAINERS> <CONTAINER> <PRE_HTML>DEPT_PREHTML</PRE_HTML> <TITLE>Departments</TITLE> <POST_HTML>DEPT_POSTHTML</POST_HTML> </CONTAINER> <CONTAINER> <PRE_HTML>EMP_PREHTML</PRE_HTML> <TITLE>Employees</TITLE> <POST_HTML>EMP_POSTHTML</POST_HTML> </CONTAINER> </CONTAINERS> So, every container has a PRE_HTML and POST_HTML element which references other nodes in my XML. For example, the Departments container references the DEPT_PREHTML and DEPT_POSTHTML nodes. The DEPT_PREHTML and DEPT_POSTHMTL nodes look as shown: <DEPT_PREHTML> <DIV id="Layer1" style="position: absolute" <IMG src="/images/edu.gif" width="917" height="104"/> </DIV> </DEPT_PREHTML> <DEPT_POSTHTML> <!-- Some more well formed HTML. --> </DEPT_POSTHTML> Similarly, EMP_PREHTML and EMP_POSTHTML contain well-formed HTML. In my XSL, I would like to iterate through each of the containers and spit out the well-formed HTML which is sitting in the respective PRE_HTML and POST_HTML nodes. However, I am not having any luck dereferencing the node name that is the value of an element. In the XSL, I am using the xsl:copy-of to spit out the node specified by the PRE_HTML and POST_HTML elements of the CONTAINER. But, this does not work. The XSL looks as shown below: <xsl:template match="/CONTAINERS"> <xsl:for-each select="CONTAINER"> <xsl:copy-of select="PRE_HTML" <xsl:apply-templates select="*|@*|text()"/> </xsl:copy-of> <!-- Do some more things here --> <xsl:copy-of select="POST_HTML" <xsl:apply-templates select="*|@*|text()"/> </xsl:copy-of> </xsl:for-each> </xsl:template> Can somebody shed any light on this? How do I spit out the well-formed HTML sitting in various nodes that are referenced by the PRE_HTML and POST_HTML elements? Thanks in advance, Sanjay XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: EZ/X Speed:, Rick Ross | Thread | How to get &, Stephane St-Denis |
RE: EZ/X Speed:, Kay Michael | Date | RE: EZ/X Speed:, Sebastian Rahtz |
Month |