xsl-list
[Top] [All Lists]

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

2007-06-01 07:36:48
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(_at_)optusnet(_dot_)com(_dot_)au] 
Sent: 01 June 2007 15:03
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] FW: Getting a flat mapping of XSLT fields for 
documentation purposes...



From: Minas Casiou [mailto:minas(_at_)optusnet(_dot_)com(_dot_)au]
Sent: Friday, 1 June 2007 11:57 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
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(_at_)police(_dot_)nsw(_dot_)gov(_dot_)au 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.




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>