RE: [xsl] FW: Getting a flat mapping of XSLT fields for documentation purposes...

Subject: RE: [xsl] FW: Getting a flat mapping of XSLT fields for documentation purposes...
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 1 Jun 2007 15:36:15 +0100
The general problem is insoluble, in the sense that a sufficiently well
obfuscated stylesheet could conceal its run-time behaviour from any static
analyzer. So you'll have to confine yourself to heuristics, that is,
detecting common coding patterns and reporting on them.

It's then just a question of how far you want to go. For example, you could
probably handle 80% of all cases by looking at each element constructor
(literal result element, or xsl:element with a fixed name attribute) and
reporting what kind of element is selected by the nearest enclosing
xsl:for-each or xsl:template with a match pattern. If the element is
constructed in a named template, you could recurse to the places where that
template is called, but that's a bit more ambitious.

I don't think that knowledge of the schema is going to help you very much.
In theory it can help you do a deeper analysis, but it becomes a couple of
orders of magnitude more complex.

Since the purpose is documentation, have you considered run-time analysis
instead? For example the XML trace file that Saxon produces with the -T
option can yield a lot of information.

Michael Kay 
http://www.saxonica.com/


> -----Original Message-----
> From: Minas Casiou [mailto:minas@xxxxxxxxxxxxxxx] 
> Sent: 01 June 2007 15:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] FW: Getting a flat mapping of XSLT fields for 
> documentation purposes...
> 
> 
> 
> From: Minas Casiou [mailto:minas@xxxxxxxxxxxxxxx]
> Sent: Friday, 1 June 2007 11:57 PM
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Cc: 'Minas Casiou'
> Subject: Getting a flat mapping of XSLT fields for 
> documentation purposes...
> 
> Hi,
> I'm trying to put together an XSLT which will take an 
> arbitrary XSLT (that maps data from one XSD schema to another 
> XSD schema), and provides (on a best-effort basis) a flat 
> view of the mapping from the point of view of the XSD being 
> mapped to. 
> 
> i.e. 
> If I've got 3 files: 
>         1)XSDInput.xsd - defines input data format 
>         2)XSDOutput.xsd - defines output data format and 
>         3)XSLTmapper.xslt - maps from input data format 
> (XSDInput.xsd) to output data format (XSDOutput.xsd) 
> 
> I want to create a generic XSLT file: 
>         - -> XSLTFlatMappingForDoco.xslt 
> that takes various         
>         XSLTMapper.xslt
> files, and produces something like: 
> 
> <Maps>
> <Map>
>   <from>s1:StreetName</from>
>   <to>s0:Pda_Inf_Street_Name</to>
> </Map>
> <Map>
>   <from>s1:StreetType</from>
>   <to>s0:Pda_Inf_Street_Type</to>
> </Map>
> <Map>
>   <from>s1:StreetSuffix1</from>
>   <from>s1:StreetSuffix2</from>
>   <to>s0:Pda_Inf_Street_Suffix</to>
> </Map>
> .... 
> </Maps>
> 
> which says that field 
>         s0:Pda_Inf_Street_Name
> comes from: 
>         s2:StreetName         
> 
> and
>   <from>s1:StreetSuffix1</from>
>   <from>s1:StreetSuffix2</from>
>   <to>s0:Pda_Inf_Street_Suffix</to> 
> 
>         s0:Pda_Inf_Street_Suffix
> comes from: 
>         s1:StreetSuffix1 
>         s1:StreetSuffix2 
> 
> etc. 
> 
> Any other additional info would be a bonus, but I'm not too 
> fussed about that right now...bigger problems trying to do 
> just the above! 
> 
> I've got this so far... 
> 
> <?xml version='1.0' ?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
> xmlns:s0="URN:AU.GOV.NSW.POLICE.XML.SERVICE.APPLICATION.COPSEV
> ENT.CAD400NWS.VERSION_1_0_0"> 
>         <xsl:output method="xml" encoding="UTF-8" indent="yes"/> 
>         
>         <xsl:template match="*"> 
>         <Maps> 
>                 <xsl:for-each 
> select="descendant-or-self::xsl:value-of"> 
>                         <Map> 
>                                 <from> 
>                                         <xsl:value-of 
> select="../../parent::xsl:for-each/@select"/> 
>                                 </from> 
>                                 <to> 
>                                         <xsl:value-of 
> select="name(../.)"/> 
>                                 </to> 
>                         </Map> 
>                 </xsl:for-each> 
>         </Maps> 
>         </xsl:template>
> </xsl:stylesheet> 
>   
> which sort of does a liiiiitle bit of the job (completely 
> useless at this point...). 
> 
> Has anyone done this sort of thing before, or know how to 
> approach it? 
> I'm completely lost for how to do it using XSLT. I don't want 
> to have to resort to code. I suspect that'll be even uglier. 
> 
> Thanks 
> 
> 
>   
> Cheers 
>   
> Minas Casiou |  ESB Technical Architect I&I | MRP -  
> Mainframe Replacement Program    |  BTS  |  New  South  Wales  Police 
> Phone: 02 9689 7610 |  Eaglenet: 79610  |  Mobile: 0431 103 
> 925  |  email: casi1min@xxxxxxxxxxxxxxxxx This message and 
> any attachment is confidential and may be privileged or 
> otherwise protected from disclosure. If you have received it 
> by mistake, please let us know by reply and then delete it 
> from your system; you should not copy the message or disclose 
> its contents to anyone.

Current Thread