I have to fill 20 total elements with XSLT in my XML code I have a & lt; Select & gt;
With values, do not have 20 forms to write?
My XML:
& lt; Production & gt; & Lt; Gt selection and; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; Name & gt; A & lt; / Name & gt; & Lt; / Select & gt; & Lt; Gt selection and; & Lt; ID & gt; 2 & lt; / Id & gt; & Lt; Name & gt; Two & lt; / Name & gt; & Lt; / Select & gt; & Lt; Gt selection and; & Lt; ID & gt; 3 & lt; / Id & gt; & Lt; Name & gt; Three & lt; / Name & gt; & Lt; / Select & gt; & Lt ;! - One more - & gt; & Lt; / Product & gt;
My XSLT:
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/transform" & gt; & Lt; Xsl: template match = "/" & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; Select name = "value []" & gt; & Lt; Option value = "0" & gt; & Lt; / Options & gt; & Lt; Xsl: each selection = "output / select" & gt; & Lt; Option & gt; & Lt; Xsl: attribute name = "value" & gt; & Lt; Xsl: Select Value = "id" & gt; & Lt; / Xsl: attribute & gt; & Lt; Xsl: Select the value = "name" /> & Lt; / Options & gt; & Lt; / For XSL: - Each & gt; & Lt; / Select & gt; & Lt; / Body & gt; & Lt; / Html & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
desired output:
& lt; Html & gt; & Lt; Body & gt; & Lt; Select name = "value []" & gt; & Lt; Option value = "0" & gt; & Lt; / Options & gt; & Lt; Option value = "1" & gt; A & lt; / Options & gt; & Lt; Option value = "2" & gt; Two & lt; / Options & gt; & Lt; Option value = "3" & gt; Three & lt; / Options & gt; & Lt; / Select & gt; & Lt ;! - but 20 times - & gt; & Lt; / Body & gt; & Lt; / Html & gt;
First of all, for the template instead of
Use, you can use the reconstructive template call to simulate the loop (as seen):
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/transform" & gt; & Lt; Xsl: template match = "/" & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; Xsl: call-template name = "selection" & gt; & Lt; Xsl: with-param name = "i" & gt; 1 & lt; / Xsl: with-param & gt; & Lt; Xsl: with-param name = "count" & gt; 20 & lt; / Xsl: with-param & gt; & Lt; / XSL: Call-templates & gt; & Lt; / Body & gt; & Lt; / Html & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: Template Name = "Selection" & gt; & Lt; Xsl: ultimate name = "i" /> & Lt; Xsl: Ultimate Name = "Calculation" /> & Lt; Xsl: if test = "$ i & lt; = $ count" & gt; & Lt; Select name = "value []" & gt; & Lt; Xsl: Apply-Select Template = "Output / Select" / & gt; & Lt; / Selection? & Lt; / XSL: If & gt; & Lt ;! - begin_: repeat TheLoopUntilFinished - & gt; & Lt; Xsl: if test = "$ i & lt; = $ count" & gt; & Lt; Xsl: call-template name = "selection" & gt; & Lt; Xsl: with-param name = "i" & gt; & Lt; Xsl: Select the value = "$ i + 1" /> & Lt; / XSL: with-param & gt; & Lt; Xsl: with param-name = "count" & gt; & Lt; Xsl: Select Value = "$ counts" /> & Lt; / XSL: with-param & gt; & Lt; / XSL: Call-templates & gt; & Lt; / XSL: If & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "output / select" & gt; & Lt; Option & gt; & Lt; Xsl: attribute name = "value" & gt; & Lt; Xsl: Select Value = "id" & gt; & Lt; / XSL: Specialty & gt; & Lt; Xsl: Select the value = "name" /> & Lt; / Options & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
Comments
Post a Comment