Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 February 6th, 2006, 09:36 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default statically embedding a stylesheet within another s

Given AStyleSheet.xsl :

<AStyleSheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns="http://www.mytest.mytest2.mytest3.com" version="1.0">
 <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
            <xsl:element name="Test">it works</xsl:element>
        </xsl:template>
</xsl:stylesheet>
</AStyleSheet>

I am trying to embedding the style sheet within another style sheet as below. If I am using <xsl:copy-of select="document('AStyleSheet.xsl')"/>, it works ok. But I am having trouble doing the static embedding of the style sheet as below. Any idea how to allow static embedding?

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<Root>
  <Data>test stylesheet embedding</Data>
  <!--dynamic embedding works:
      <xsl:copy-of select="document('AStyleSheet.xsl')"/>
  -->

  <AStyleSheet>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns="http://www.mytest.mytest2.mytest3.com"version="1.0">
    <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
            <xsl:element name="Test">it works</xsl:element>
        </xsl:template>
    </xsl:stylesheet>
  </AStyleSheet>
</Root>
</xsl:template>
</xsl:stylesheet>

I suspecting the difference between dynamic stylesheet copy through select="document..." vs. static stylesheet creation by elements is an issue of namespace. What are their respective namespace? And how can I achieve same the namespace?

 
Old February 6th, 2006, 10:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Elements in the XSL namespace are always taken as instructions, not as literal result elements.

Have a look at xsl:namespace-alias.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 6th, 2006, 11:02 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I chang the namespace within <AStyleSheet> from .../Transfrom to .../Transform2 as following:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform2"
        xmlns="http://www.mytest.mytest2.mytest3.com" version="1.0">

Things appear to work. But I don't have right namespace!

If the issue is not namespace related, any other theory to make the static embedding work?



 
Old February 6th, 2006, 11:41 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Did you read my answer and not understand it, or didn't you read it?

What are you actually trying to achieve? Why do you want to embed one stylesheet within another?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 6th, 2006, 01:38 PM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Michael Kay;

Sorry. I did read your response and also read the http://www.w3schools.com/xsl/el_namespace-alias.asp; but I think I didn't got it as I could not get it to work.

I know you have good intension to help me out. I could not provide more detail "Why do you want to embed one stylesheet within another?" But basically the second stylesheet is the one our end user really uses and it is required.

I am new to this forum and not sure how to email you directly. Please feel free to email me at [email protected]; so that I can provide you more details if desired.

Sincerely;

David Li

 
Old February 6th, 2006, 01:48 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

But why don't you xsl:include or xsl:import the sheet?

--

Joe (Microsoft MVP - XML)
 
Old February 6th, 2006, 02:01 PM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Both of the include or import uses of URI as below:

<xsl:import href="URI"/>
 (http://www.w3schools.com/xsl/el_import.asp)
<xsl:include href="URI"/> (http://www.w3schools.com/xsl/el_include.asp)

The point I want to make is that I don't want to link to another stylesheet document dynamically. And I just want to copy the content of the stylesheet to be copied in statically.

Basically, I see the following error message when I do static copy:

"Xsl Compile: 'xsl:stylesheet' cannot be a child of "AStyleSheet' element." More clues?

 
Old February 7th, 2006, 07:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks to me as if you are trying to write a stylesheet that produces a stylesheet as its output. Is that correct? (If so, why couldn't you say so?)

If that's the case, then you need to use xsl:namespace-alias. There are examples of doing this in the XSLT spec itself or in any good reference book.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 7th, 2006, 09:14 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, you are right that I want to "write a stylesheet that produces a stylesheet as its output." And this is to be done "statically". Sorry that I was not able to describe the question more effectively as I am really a newbie in XSLT.

I will lookup the xsl:namespace-alias for more details; and I will search the XSLT spec and/or reference books for examples.

However, would you please kindly provide the link(s) if it is readily available to you?

 
Old February 7th, 2006, 12:28 PM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Michael Kay;

I am able to follow the example below as from http://www.w3.org/TR/xslt:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">

<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>

<xsl:template match="/">
  <axsl:stylesheet>
    <xsl:apply-templates/>
  </axsl:stylesheet>
</xsl:template>

...

Now, I am all set. Thank you for all the help.

Sincerely;

David Li






Similar Threads
Thread Thread Starter Forum Replies Last Post
File embedding in vbasic(Please help ) dextergaisie Pro VB 6 1 September 21st, 2007 11:47 AM
Embedding a wmv file arimakidd HTML Code Clinic 1 March 27th, 2007 04:32 PM
Embedding rajkumar007 Classic ASP Basics 0 October 15th, 2005 07:33 AM
Embedding Excel Spreadsheet in C# Hitesh_Golyan C# 1 December 2nd, 2004 09:59 AM





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