Sunday 15 September 2013

How to create XSLT transformation for srcML? -


I have a question about XSL conversions. Takes an example (in SOML), which represents a typed EF in C:

   

C Edition:

  TypeFIFNAM FNM {Value0 = 0, value1 = SOMECONST, value2 = SOMECONST + 1, valutop} TSAMANM;  

For example, Value2 ?

to remove the line with & lt; Xsl: template & gt; How to define

& lt; to delete the previous row (with the ValueTop ), including the previous comma. Xsl: template & gt; How to define

This is a bit difficult due to the nature of the "intersection text" of your input XML Especially handling a comma is not trivial, and my proposed solution is probably wrong (even if it works for this particular input), the syntax is complex and I do not know much about srcML because I have a comma handling part I advise to give a lot of thought.

Still, my attempt is to do it.

  & lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: src = "http://www.sdml.info/srcml/src" Xmlns = "Http://www.sdml.info/srcml/src" & gt; & Lt ;! - The identity template is all copied as - & gt; & Lt; Xsl: template match = "node () | @ *" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "node () | @ *" /> & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt ;! - Removes any matching element from empty template output - & gt; & Lt; Xsl: template match = "src: XPP [src: name = 'value2']" /> & Lt; Xsl: template match = "src: expr [last] ()]" /> & Lt ;! - This template handles comta after expression - & gt; & Lt; Xsl: template match = "text () [normal-location () = ',']" & gt; & Lt ;! - Select the following node, but only if it & lt; Expr & gt; Element - & gt; & Lt; Select xsl: variable name = "expr" = "following-sibling :: * [1] [self: source: expr]" /> & Lt ;! - Apply template for this, save result - & gt; & Lt; Xsl: variable name = "check" & gt; & Lt; Xsl: Choose Apply-Template = "$ expr" /> & Lt; / XSL: variable & gt; & Lt ;! - If something was returned, then this comma needs to be copied - & gt; & Lt; Xsl: if test = "$ check! = ''" & Gt; & Lt; Xsl: Copy / & gt; & Lt; / XSL: If & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;  

was my input (I used the srcML namespace for example):

  & lt; Unit xmlns = "http: // www. Sdml.info/srcml/src"> & Lt; Typedef & gt; Typeface & lt; Type & gt; & Lt; Enum & gt; Anem & lt; Name & gt; Some anemm & lt; / Name & gt; & Lt; Block & gt; {& Lt; Expr & gt; & Lt; Name & gt; Value 0 & lt; / Name & gt; = 0 & lt; / Expr & gt ;, & lt; Expr & gt; & Lt; Name & gt; Value 1 & lt; / Name & gt; = & Lt; Name & gt; SOMECONST & lt; / Name & gt; & Lt; / Expr & gt ;, & lt; Expr & gt; & Lt; Name & gt; Price 2 & lt; / Name & gt; = & Lt; Name & gt; SOMECONST & lt; / Name & gt; + 1 & lt; / Expr & gt ;, & lt; Expr & gt; & Lt; Name & gt; Price type & lt; / Name & gt; & Lt; / Expr & gt; } & Lt; / Block & gt; & Lt; / Enum & gt; & Lt; / Type & gt; & Lt; Name & gt; TSomeEnum & lt; / Name & gt; & Lt; / Typedef & gt; & Lt; / Unit  

More results:

  & lt; Unit xmlns = "http://www.sdml.info/srcml/src" & gt; & Lt; Typedef & gt; Typeface & lt; Type & gt; & Lt; Enum & gt; Anem & lt; Name & gt; Some anemm & lt; / Name & gt; & Lt; Block & gt; {& Lt; Expr & gt; & Lt; Name & gt; Value 0 & lt; / Name & gt; = 0 & lt; / Expr & gt ;, & lt; Expr & gt; & Lt; Name & gt; Value 1 & lt; / Name & gt; = & Lt; Name & gt; SOMECONST & lt; / Name & gt; & Lt; / Expr & gt; } & Lt; / Block & gt; & Lt; / Enum & gt; & Lt; / Type & gt; & Lt; Name & gt; TSomeEnum & lt; / Name & gt; & Lt; / Typedef & gt; & Lt; / Unit & gt;  

No comments:

Post a Comment