1

I have an XML file which is being processed by XSLT, to produce another XML file.

Is there a simple way to know all of the possible elements/attributes in the original XML message that the XSLT will reference in order to produce the output file?

If I look at the example on the w3school.com site (http://www.w3schools.com/xsl/xsl_transformation.asp) then the catalogue XML contains items like price and year, but the XSLT will only pull catalog/cd/title and catalog/cd/artist.

So what I need is some kind of automated magic tool that can analyse xslt (maybe the input file schemas) to give me some kind of list of attributes that the output file will contain.

Thanks for any assistance

Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114
Ian V
  • 23
  • 2
  • 1
    Look at your computer and say "autokazam" and it should work like magic... – Tschallacka Dec 06 '12 at 10:13
  • Ian V, You accepted an answer that says that there are no such tools. Did you read my answer, which shows that what you want is actually possible and easy, and shows exactly how to do this? – Dimitre Novatchev Dec 09 '12 at 17:39

3 Answers3

0

if you change your xslt file to this

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

it will show you a copy of the original file if that is any help?

Treemonkey
  • 2,133
  • 11
  • 24
0

good imagination though! Well. Currently there are no such tools available which can analyse XSLT and let you know like 'what all element/attribute it is referring in an XML file'! You have to do it manually ..

Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114
  • Thanks for the update. My problem is that the main XSLT that I want to analyse is 12,000 lines long, and contains templates chained to templates. It will take weeks to analyse, hence the request for a tool that can help. Thanks for the response (and edit) – Ian V Dec 06 '12 at 11:55
  • @IanV, you are welcome, I will see if I can find **any** tool that atleast provides a good view.. (like for XML there is XMLPad, instead of showing XML as code it shows as a tree, which makes user understand it more).. I will for sure search for anything such that.. – Rookie Programmer Aravind Dec 06 '12 at 13:07
0

It isn't difficult to produce such tool yourself:

Add to any template that matches element(s) or attribute(s):

<xsl:message>
 <!-- Put all the data here that identifies the element attribute,
      for example the Xpath expression that selects the current node
 -->
</xsl:message>

You can use existing transformations that take a node and produce one XPath expression that selects the node -- invoke them inside the above xsl:message. See for example this: Generate/get xpath from XML node java

Then what you need to do is to combine all these generated XPath expressions with the | operator and to evaluate the resulting XPath expression -- this will select all elements and attributes that are actually referenced in the transformation.

If you also want to account for the elements/attributes that are processed by the XSLT built-in templates, simply override those with specific templates in your transformation -- this is a good practice that as additional benefit may find errors in your transformation.

Community
  • 1
  • 1
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431