Dynamically add XML tags to be processed?

B

bjam

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>

.....
 
D

David Carlisle

bjam said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top