Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2006, 09:05 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transform an XSL sheet

I work with transforming XML sheets via XSLT sheets. The devlopment of said sheets is getting outsourced, so I need to document the XSL sheets. I'm trying to do this via creating ANOTHER XSL sheet to read the XSLT sheet and create a dynamic XHTML page for documentation. This way I can just plug all my common functions in and save myself a lot of tedious work.

Does anyone know if this is possible, and how I would go about it? I can figure out which information to get, I just don't know how to transform another XSL sheet. The xls: is screwing me up.

Thanks in advance.

(I'm using Altova XMLSpy)
 
Old June 30th, 2006, 09:35 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

This transform will list attributes of all xsl:template elements when run against an XSLT document:
Code:
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates select="*/xsl:template"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="xsl:template">
    <p>Template:
    <div>
      match:#xa0;<xsl:value-of select="@match"/>
    </div>
    <div>
      name:#xa0;<xsl:value-of select="@name"/>
    </div>
    </p>
  </xsl:template>
</xsl:stylesheet>
--

Joe (Microsoft MVP - XML)
 
Old June 30th, 2006, 11:32 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Creating elements in the XSLT namespace can be a bit tricky (you either need to use xsl:element, or to define a namespace alias). However, reading a stylesheet is just like reading any other document. As always, it's hard to tell what you're doing wrong if you don't tell us what you are doing or what error messages you are getting.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 5th, 2006, 11:28 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I realize I probably should've included an example of what I'm trying to do. Here's a piece of the original XSL.

Code:
<xsl:template name="CurrentDateTimeAsRECORD">
    <xsl:param name="qualifier"/>
    <xsl:param name="currentDateTime"><xsl:value-of select="fn:current-dateTime()"/></xsl:param>
        <DATETIME>
            <xsl:attribute name="qualifier"><xsl:value-of select="$qualifier"/></xsl:attribute>
            <YEAR><xsl:value-of select="fn:year-from-dateTime($currentDateTime)"/></YEAR>
            <MONTH><xsl:value-of select="fn:month-from-dateTime($currentDateTime)"/></MONTH>
            <DAY><xsl:value-of select="fn:day-from-dateTime($currentDateTime)"/></DAY>
            <HOUR><xsl:value-of select="fn:hours-from-dateTime($currentDateTime)"/></HOUR> 
            <MINUTE><xsl:value-of select="fn:minutes-from-dateTime($currentDateTime)"/></MINUTE>
            <SECOND><xsl:value-of select="fn:seconds-from-dateTime($currentDateTime)"/></SECOND>
            <SUBSECOND>0</SUBSECOND>
            <TIMEZONE><xsl:value-of select="format-number(fn:hours-from-duration(fn:timezone-from-dateTime($currentDateTime)),'00')"/>:<xsl:value-of select="format-number(fn:minutes-from-duration(fn:timezone-from-dateTime($currentDateTime)),'00')"/></TIMEZONE>
        </DATETIME>
</xsl:template>



I tried the code from the first reply and it returned only the name of the template (although it's pretty easy to see that now that I look at it). I tried to modify it to give me more information, but to no avail.

I'm trying to get everything that is called from date-time function, i.e. the month, day, and hour. Pretty much all the values.

 
Old July 5th, 2006, 11:53 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you need to analyze the content inside the XPath expressions, then you need to write an XPath parser, and that isn't a job to tackle in XSLT.

You might try looking at David Carlisle's code that takes XQuery (of which XPath is a subset) and turns it into XQueryX, which is an XML representation of the parse tree. You could then analyse the resulting XQueryX document using XSLT/XPath.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 5th, 2006, 04:18 PM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, It's not that I need to analyze WHAT the XPath functions are doing, rather just WHICH functions are used.
The final result will be the name of the sheet, input, and output.

The output would be things like DAY, HOUR, MINUTE - just the tags for the final xml document. The input would be $current-dateTime, or everything in between those previously mentioned tags.

 
Old July 5th, 2006, 04:31 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think I've lost the thread. I thought you were trying to document real stylesheets, in which case the functions that you call in an XPath expression are unrelated to the names of the elements in which those calls appear.

Anyway, getting the names of the elements is trivial, you just want something like //*/name().

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 6th, 2006, 09:58 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I'm sorry I lost you.

Let's say my code is
Code:
<xsl:param name="currentDateTime"><xsl:value-of select="fn:current-dateTime()"/></xsl:param>
<YEAR><xsl:value-of select="fn:year-from-dateTime($currentDateTime)"/></YEAR>
I'm creating a new XSL document to output a simple table that looks like:

Code:
|      Input      |   Output   |    Output value     |
|$currentDateTime |    YEAR    |fn:year-from-dateTime|
I have a lot of documents in much the same format as this, I'm trying to figure out how to extract the names of that first parameter, the name of the tags, and what's in between the tags.

I tried using //*/name() but I don't think I'm using the right syntax with it, and I can't find how to correctly use it.

(I'm sorry for being a confusing novice)

 
Old July 6th, 2006, 10:21 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can show the names of the literal result elements output by each template like this:

<xsl:template match="xsl:template">
  <h2><xsl:text>Template</xsl:text>
    <xsl:if test="@name"> name = <xsl:value-of select="@name"/></xsl:if>
    <xsl:if test="@match"> name = <xsl:value-of select="@match"/></xsl:if>
  </h2>
  <p>Literal result elements constructed:</p>
  [list]
  <xsl:for-each select=".//* except .//xsl:*">
    <li><xsl:value-of select="name()"/></li>
  </xsl:for-each>
  </ul>

If you now want to look at what is constructed as the content of each literal result element, you will have to look inside the @select expressions of the xsl:value-of instructions. Since these contain general XPath expressions, you will have to parse the expressions, as I explained in a previous email. This is not an easy job to do in XSLT. You could do some cheap-and-dirty analysis, for example if all your function calls are prefixed "fn:" (I can't understand why anyone wants to use this prefix, but never mind) then you could extract the text between "fn:" and "(" by regular expression matching. You might get some false hits, but I expect you can live with that.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser transform using local XSL and remote XML sosarder XSLT 1 March 13th, 2007 02:58 PM
How do you transform a XML SOAP Response using XSL wsessoms VB How-To 0 December 20th, 2006 08:21 AM
Removing Namespaces from XSL Transform output francislang XSLT 2 September 7th, 2004 07:58 AM
How can XSL transform XHTML data into fragments? lamwh XSLT 0 April 19th, 2004 10:15 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.