I have a problem I get data from XML and it changes with xslt.
Say I have an XML file:
& Lt; / Address & gt; & Lt; Address type = "business" & gt; & Lt; Street & gt; 1234 Lottworks Avenue & Lt; / Road & gt; & Lt; City & gt; Anytown & lt; / City & gt; & Lt; Zip & gt; 85,786 & lt; / Zip> & Lt; / Address & gt; & Lt; / Row & gt; & Lt; Line id = "2" fname = "elen" lname = "wahlin" & gt; & Lt; Address type = "home" & gt; & Lt; Road & gt; 1234 St. and Lieutenant; / Road & gt; & Lt; City & gt; Anytown & lt; / City & gt; & Lt; Zip & gt; 85,789 & lt; / Zip> & Lt; / Address & gt; & Lt; Address type = "business" & gt; & Lt; Road & gt; 1233 Books Path & lt; / Street & gt; & Lt; City & gt; Anytown & lt; / City & gt; & Lt; Zip & gt; 85,784 & lt; / Zip> & Lt; / Address & gt; & Lt; / Row & gt; & Lt; / Root & gt; And this stylesheet:
& lt ;? XML version = "1.0"? & Gt; & Lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" & gt; & Lt; Xsl: output method = "xml" indent = "yes" encoding = "UTF-8" omit-xml-declaration = "no" /> & Lt; Xsl: template match = "/" & gt; & Lt; Root & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / Root & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "row" & gt; & Lt; Line & gt; & Lt; Xsl: attribute name = "id" & gt; & Lt; Xsl: Select Value = "id" /> & Lt; / XSL: Specialty & gt; & Lt; Xsl: attribute name = "fname" & gt; & Lt; Xsl: Select the value = "name / fan" /> & Lt; / XSL: Specialty & gt; & Lt; Xsl: attribute name = "lname" & gt; & Lt; Xsl: Select the value = "name / l name" /> & Lt; / XSL: Specialty & gt; & Lt; Xsl: each selection = "address" & gt; & Lt; Xsl: copy-of select = "." / & Gt; & Lt; / XSL: for-each & gt; & Lt; / Row & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt; How can it limit the 3 records, then after 3 records can it make an RR tag?
For example:
& lt; Table & gt; & Lt; TR & gt; & Lt; TD & gt; Address 1 & lt; / TD & gt; & Lt; TD & gt; Address 2 & lt; / TD & gt; & Lt; TD & gt; Address 3 & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Address4 & lt; / TD & gt; & Lt; TD & gt; Address5 & lt; / TD & gt; & Lt; TD & gt; Address6 & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; Instead of
:
& lt; Xsl: each selection = "address" & gt; & Lt; Xsl: copy-of select = "." / & Gt; & Lt; / XSL: for-each & gt; You should do something like this:
& lt; Xsl: each selection = "address" & gt; & Lt; Xsl: if test = "position () mod 3 = 1" & gt; & Lt; TR & gt; & Lt; Xsl: call-template name = "print address" & gt; & Lt; With xsl: select param name = "address" = "." / & Gt; & Lt; / XSL: Call-templates & gt; & Lt; Xsl: call-template name = "print address" & gt; & Lt; With xsl: select param name = "address" = "lower-speech :: * [position () = 1]" /> & Lt; / XSL: Call-templates & gt; & Lt; Xsl: call-template name = "print address" & gt; & Lt; With xsl: select param name = "address" = "lower-sibling :: * [position () = 2]" /> & Lt; / XSL: Call-templates & gt; & Lt; / TR & gt; & Lt; / XSL: If & gt; & Lt; / XSL: for-each & gt; And of course you should have a template print address anywhere.
It should give you an idea about how to solve it. The point is to process every N-th item (depending on the process) mod n) and process of the following items at once (selected by the following-sibling :: * [position (= ==) , Wrap them in tr. Note that it is important to compare the mode result with 1, because the position begins with 1.
Comments
Post a Comment