xml - change variable value in xsl -
I have a problem with XSL variables, I know that once the variable is declared, the value of variable counts can be changed is.
But I am facing a strange problem and I can not possibly change the XML output, instead it is possible that with XSL only possible.
I am using xsl: for each loop on some data for XML
There may be three types of extinction data, Type 1, Type 2 and Type 3
If it is Type1, then I would like to process that data I'm saying the template. Inside the template I am displaying a header, I need to print this header for the first time, when I am only experiencing this Type1 data. After this I do not need to display it.
I could pass a parameter with a call-template and set / unset to decide if I need to print header text. But as I think, being a formatting language, variable position is not preserved.
Can you please provide your valuable suggestions on implementing it (possibly without XML changes)?
Edit:
The test will work for XML output described by Patrice. But my XML is different
With this XML, I need to display a header for the first time to face 'O Fu'. The sequence of items can also be anything I can not really predict when 'foo' will appear in the XML.
Can you please bring any suggestions?
You can use a proper selector for it (you will be easier with some actual code ).
Example with this input:
& lt; Doc & gt; & Lt; Items & gt; Foo & lt; / Item & gt; & Lt; Items & gt; Bar & lt; / Item & gt; & Lt; / Doc & gt;
You can use this XSLT:
& lt; Xsl: stylesheet version = '1.0' xmlns: xsl = 'http: //www.w3. Org / 1999 / XSL / conversion '& gt; & Lt; Xsl: output method = 'html' version = '1.0' encoding = 'UTF-8' indent = 'yes' /> & Lt; Xsl: template match = "/" & gt; & Lt; Xsl: Apply-Select Template = "/ Doctor / Object" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "item" & gt; & Lt; Xsl: if test = "no (predecessor-cybling :: item)" & gt; & Lt; H1 & gt; First & lt; / H1> & Lt; / XSL: If & gt; & Lt; P & gt; & Lt; Xsl: applied-template / & gt; & Lt; / P & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
And you will get this output:
& lt; H1 & gt; First & lt; / H1> & Lt; P & gt; Foo & lt; / P & gt; & Lt; P & gt; Bar & lt; / P & gt;
This is a test of keys
& lt; Xsl: if test = "no (predecessor-sibling :: item)" & gt;
You can do this by
& lt; Xsl: if test = "no (predecessor :: item)" can also be changed.
Comments
Post a Comment