Dynamically add XML tags to be processed?

Discussion in 'XML' started by bjam, Apr 12, 2005.

  1. bjam

    bjam Guest

    Hi, I am trying to create a sort of include file into my xsl files such
    that calling the following template will push these xml tags into my
    document such that the other xsl files can use these tags to make
    decisions. In this case I want antother template that is going to
    create tables be able to call this template in order to get information
    for the various table paramaters and then use xsl:attribute to push
    items into the table tag. Does anyone know if there is a way to
    dynamically create xml tags using xsl in the document such that the
    rest of the xsl style sheet processing can use these tags? Below is
    the template file I am looking to create ... and further below is it's
    usuage.

    <!-- please note this is experimental -->
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!-- import the data output template for displaying each row of resutls
    -->

    <!-- table settings -->
    <!-- border="0" cellpadding="2" cellspacing="0" bgcolor="lightblue"
    width="50%"-->
    <xsl:template name="summary_table_specs">
    <xml_summary_table cellpadding='2'/>
    <xml_summary_table cellspacing='6'/>
    <xml_summary_table border='3'/>
    <xml_summary_table width='100%'/>
    <xml_summary_table bgcolor='lightblue'/>
    </xsl:template>


    </xsl:stylesheet>

    ......... usage below

    <xsl:import="summary_table.xsl">
    <xsl:call-template name="summary_table_specs"/>
    <table>
    <xsl:attribute href="cellpadding">
    <xsl:value-of select="/xml_summary_table[@cellpadding][text()]"/>
    </xsl:attribute>

    .....
    bjam, Apr 12, 2005
    #1
    1. Advertising

  2. "bjam" <> writes:

    > Hi, I am trying to create a sort of include file into my xsl files such
    > that calling the following template will push these xml tags into my
    > document


    It's hard to follow what you mean here. XSLT doesn't have any access to
    tags in the source files, it just has access to a node tree generated by
    an XML parser which has processed (and discarded) the tags.

    > such that the other xsl files can use these tags to make
    > decisions. In this case I want antother template that is going to
    > create tables be able to call this template in order to get information
    > for the various table paramaters and then use xsl:attribute to push
    > items into the table tag. Does anyone know if there is a way to
    > dynamically create xml tags using xsl in the document such that the
    > rest of the xsl style sheet processing can use these tags? Below is
    > the template file I am looking to create ... and further below is it's
    > usuage.
    >


    > <!-- please note this is experimental -->
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >
    > <!-- import the data output template for displaying each row of resutls
    > -->
    >
    > <!-- table settings -->
    > <!-- border="0" cellpadding="2" cellspacing="0" bgcolor="lightblue"
    > width="50%"-->
    > <xsl:template name="summary_table_specs">
    > <xml_summary_table cellpadding='2'/>
    > <xml_summary_table cellspacing='6'/>
    > <xml_summary_table border='3'/>
    > <xml_summary_table width='100%'/>
    > <xml_summary_table bgcolor='lightblue'/>
    > </xsl:template>
    >
    >
    > </xsl:stylesheet>
    >
    > ........ usage below
    >
    > <xsl:import="summary_table.xsl">
    > <xsl:call-template name="summary_table_specs"/>
    > <table>
    > <xsl:attribute href="cellpadding">
    > <xsl:value-of select="/xml_summary_table[@cellpadding][text()]"/>
    > </xsl:attribute>
    >
    > ....



    Looking at the example then perhaps what you want to do is put the
    following in to a file table.xml alongside your stylesheet
    <foo>
    <summary_table cellpadding='2'/>
    <summary_table cellspacing='6'/>
    <summary_table border='3'/>
    <summary_table width='100%'/>
    <summary_table bgcolor='lightblue'/>
    </foo>
    Note that you shouldn't (or with some parsers can not) use an element
    name xml_summary_table as all names starting with xml (or XML) are
    reserved.

    Then you can do

    <table>
    <xsl:copy-of select="document('table.xml')/summary_table/@cellpadding"/>


    Or depending what you want to do, perhaps you don't want this lookup
    table at all and want to use an attribute set
    http://www.w3.org/TR/xslt#attribute-sets

    David
    David Carlisle, Apr 13, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    0
    Views:
    428
    John Saunders
    Jul 23, 2003
  2. Anibal Acosta
    Replies:
    2
    Views:
    354
    Anibal Acosta
    Feb 20, 2004
  3. Heide Ebert
    Replies:
    0
    Views:
    765
    Heide Ebert
    Jul 15, 2003
  4. Marc
    Replies:
    1
    Views:
    498
    Johannes Koch
    Aug 19, 2004
  5. Leon
    Replies:
    1
    Views:
    338
Loading...

Share This Page