PDA

View Full Version : A few of XSL questions


vw98034
06-01-2006, 04:35 PM
I have done an extended online search, but can't find solutions for thoses problems. Please help if you know the solutions, or where to find the solutions, or a better place to ask this question.

Here are the problems.

1) how to embed html tags in a XML which will be processed by XSL?

The XMLSpy doesn't let me add html tags into a par field. I let the CDATA hold the tags, but the section data won't get parsed.

2) Counter inside of xsl:for-each

With the xsl:choose tag inside of xsl:for-each tag, I need to count the number of nodes met the condition. How to set up the counter?

3) Flag inside of xsl:for-each

With the xsl:if tag inside of xsl:for-each tag, I need to know whether a node met the condition by the end of the loop. How to set up the flag variable?


Thanks very much for your information in advance.

v.

Alex Vincent
06-01-2006, 08:05 PM
I'm not sure if this is the answer you have in mind for (1), but here goes.

You can probably use the HTML tags as XHTML, which is HTML reformulated as XML. Give the root HTML tag a default namespace for XHTML, and you're good.

<div xmlns="http://www.w3.org/1999/xhtml">
<p>Hello World. This is XHTML.</p>
</div>

vw98034
06-02-2006, 12:31 AM
Thanks for your try, Alex. It, however, is not about what I ask for.

ealbrecht
06-14-2006, 09:52 PM
1) An XML file is a collection of data, or a database. Use the XSL document to process the XML data and lay it out in HTML format. If for some reason you need to include these tags in your XML file then you could try including them as CDATA.

2) You can use the position() function to test for which node you're on in your for-each statement.
<xsl:if test = "position() = 14">... ... ...</xsl:if:>

3) You cannot exit out of a for loop in XSL. You can refine your for-each query statement a little with something like this:
<xsl:for-each select="myrecord[position() &lt; 7]">