xml - "Wrap" all templates in XSLT -


I have an XSLT (1.0) stylesheet, which is a set of rules that convert XML to HTML. Here is a sample XML file that can be used in its use (in practice, XML files are more complex):

    

The XSL file takes these (often deeply nested) features and converts them into various HTML elements. Here's an (simplified) sample from the XML file:

  & lt; xsl: Template Match = "msItem [not (@style)]" & gt; & Lt; tr class = "ms-item" & gt; & Lt; td class = "num" & gt; & Lt; xsl: Select the value = "@n" /> & Lt; / Td> & Lt; td square = "locus" & gt; & Lt; xsl: Apply- Choose Template = "Locus" /> & Lt; / TD & gt; & Lt; td class = "ms-data" & gt; & Lt; Table class = "ms-item fol" & gt; & Lt; xsl: Apply-Select Template = "* [Name (.)! = 'Locus']" /> gt; & Lt; / Table & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / XSL: Templates & gt;   

Today, those powers should be decided that XML files should be bilingual and XSL should handle any language. New XML files look like this:

  & lt; msItem n = "1" & gt; & Lt; = "21r" from locus = "1r" & gt; 1r-21r & lt; / Locus & gt; & Lt; author xml: lang = "en" & gt; Anonymous & lt; / Author & gt; & Lt; author xml: lang = "it" & gt; Anonimo & lt; / Author & gt; & Lt; title xml: lang = "en" & gt; The text on the practice of measured music & lt; / Title & gt; & Lt; Title xml: lang = "it" & gt; Trateto sullÃÆ'à ¢ a, ¬ Å ¡Ãƒâ € SA, a ÃÆ'à ¢ a, ¬ Å ¡Ãƒâ € SA, a ÃÆ'à ¢ a, ¬ Å ¡Ãƒâ € SA, & Lt; / msItem & gt;   

What I've done so far is to define a stylesheet parameter ( $ lang ), which is xml: lang Attributes feature we want to process ('this' or 'n'). I want to be able to "wrap" my current template in some way like like like I do and <> & lt; xsl: template match = "*" & gt;

& lt; XSL: Select & gt; & Lt; xsl: when test = "./@ xml: lang" & gt; & Lt ;! - All elements do not have an XML: lang feature; We only want what they do - & gt; & Lt; XSL: Select & gt; & Lt; xsl: when test = "./@xml: lang = $ lang" & gt; & Lt ;! - This item is in the language we want, so process it. - & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise /> & Lt ;! - Ignore other languages ​​- & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt ;! - No xml: lang feature - & gt; & Lt; XSL: implemented-templates / & gt; & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: Templates & gt;

The problem (of course) is that it does not work, because all my other templates have got a higher priority than the wildcard here. Is there any way that I can effectively wrap this argument around my existing templates? I know that I can effectively "return" a boolean to this template, but then I'll call & lt; Xsl: when & gt; / & lt; xsl: otherwise junk every template, which I would like to save.

In XSLT 1.0 if you want, you put your new template in a different XSLT file Using the import existing code & lt; Xsl: import & gt; & lt; Xsl: applied-template / & gt; to and .

To import the templates in the importing stylesheet whenever they take preference, and to import the templates to the present node where appropriate, and import the imported stylesheet to apply-import Use.

In XSLT 2.0, you can do this by using xsl: next-match in one file, but in 1.0 you will have to use the import.

Finally, @xml: lang directly, which can control the scoping (close xml: lang in search of trees to find ) And sub-languages ​​( n-GB is a valid match when you are looking for n .

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -