XSLT applying external attributes to an element

xml

    Sponsored Links

    Next

  • 1. XSL-FO: problem with proxy authentication (error 407)
    Hi, I just get into XSL-FO using Apache fop-0.20.5. I created a small sample XML and XSL-FO file. The XML contains a node with an external URL on the web with a thumbnail image (on amazon.com). When testing at home everything works fine. Here at my company's site we must go through a proxy server (MS ISA) which requires authentication. IE is configured correctly. If created an other sample XSL to procude HTML output, IE 6.0 can show the thumbnails. Does anybody know what I must do the get Apache-fop working with the proxy server? TIA, Stefan
  • 2. Need help with re-designing the Applicant Rating template
    Hi all..., I'm redesigning the Applicant Rating templete. In its original state, it's almost perfect for my needs except for one thing; (involving the 'Job Experience' section). I'm attempting to add 3 additional line items to this section, including corresponding option buttons and would like to have these fields auto-calulate with an average as the others do. So far I've been totally unsuccessful at making this happen. Can so one assist please ? thanks in advance. - DennisO

XSLT applying external attributes to an element

Postby Kenneth » Sat, 05 Jul 2003 18:18:48 GMT

Is it possible to apply attributes from an external document to an element
in the transforming xml document.

<xsl:template match="AElement">
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
    </xsl:copy>
</xsl:template>

The above example will apply attributes to the copied AElement by the use of
"@*" (selection of all attributes).


What I'd like to accomplish is something like this:

<xsl:template match="/">
    <BElement>
        <xsl:apply-templates select="document(' http://www.**--****.com/ ')/@*"/>
    </BElement>
</xsl:template>

Copying the attributes from an external document to a new element.


Regards
Kenneth



Re: XSLT applying external attributes to an element

Postby Han » Sun, 06 Jul 2003 18:09:34 GMT

This worked for me.

<xsl:template match="/">
<root>
<xsl:apply-templates select="document('http://localhost/x.xml')//@*"/>
</root>
</xsl:template>

<xsl:template match='@*'>
 <xsl:value-of select="."/>
</xsl:template>





of



Similar Threads:

1.XSLT: how to add new elements then apply template to these elements

I have xml structure like this:

<tasks>
     <task task_id=0 parent_task_id=0 task_name='top task'>
     <task task_id=1 parent_task_id=0 task_name='task1'>
     <task task_id=2 parent_task_id=0 task_name='task2'>
     <task task_id=3 parent_task_id=0 task_name='task3'>
</tasks>

Now I need to add two more tasks into <tasks>:

<task task_id=4 parent_task_id=0 task_name='task4'>
<task task_id=5 parent_task_id=0 task_name='task5'>

Then add top task name to each sub task, for example,

<task task_id=4 parent_task_id=0 task_name='top task - task4'>

So that the result will be:

<tasks>
     <task task_id=0 parent_task_id=0 task_name='top task - top task'>
     <task task_id=1 parent_task_id=0 task_name='top task - task1'>
     <task task_id=2 parent_task_id=0 task_name='top task - task2'>
     <task task_id=3 parent_task_id=0 task_name='top task - task3'>
     <task task_id=4 parent_task_id=0 task_name='top task - task4'>
     <task task_id=5 parent_task_id=0 task_name='top task - task5'>
</tasks>

So I created two templates below (simplified).

The PROBLEM: Each works individually, but they don't work together (only 
template 2 is applied successfully, template 1 is ignored). How can I 
get around? thanks.

template 1: add new sub tasks:
-----
<xsl:template match="tasks">		
    <xsl:element name="tasks">
	<xsl:copy-of select="@*|node()"/>			
	<xsl:element name="task">
	   <xsl:attribute name="task_id">
	       <xsl:value-of select="'4'"/>
	   </xsl:attribute>
	   <xsl:attribute name="parent_task_id">
	       <xsl:value-of select="'0'"/>
	   </xsl:attribute>
	   <xsl:attribute name="task_name">
		<xsl:value-of select="'task4'"/>
	   </xsl:attribute>
    </xsl:element>		
    <xsl:element name="task">
	   <xsl:attribute name="task_id">
	       <xsl:value-of select="'5'"/>
	   </xsl:attribute>
	   <xsl:attribute name="parent_task_id">
	       <xsl:value-of select="'0'"/>
	   </xsl:attribute>
	   <xsl:attribute name="task_name">
		<xsl:value-of select="'task5'"/>
	   </xsl:attribute>
    </xsl:element>
</xsl:template>
------

template 2: append top task name to sub task name:
------
<xsl:template match="tasks/task/@task_name">	
     <xsl:variable name="top_task_id" select="../@parent_task_id"/>
     <xsl:variable name="top_task_name" 
select="../../task[@task_id=$top_task_id]/@task_name"/>
     <xsl:variable name="current_task_name" select="."/>
     <xsl:attribute name="task_name">
	<xsl:value-of select="$top_task_name"/>
         <xsl:text> -   </xsl:text>
         <xsl:value-of select="$current_task_name"/>
     </xsl:attribute>
</xsl:template>
------




2.applying CSS styles to xml elements via class attribute

My server-side php script is generating an xml response with the
following structure:

<thread class='Columns'>
<Id class='Column dataDetail'>12345</Id>
<Command class='Column dataDetail'>SET</Command>
.
.
.
</thread>

I have CSS styles defined for Columns, Column, and dataDetail like
so...

.Columns {overflow: auto; width: 100%; font-size: smaller}
.Column {position: relative; float: left; width: 100px; height: 20px;}
.dataDetail { border-top: 1px solid #c0dfc5; font-size: smaller}

But these styles don't apply to the thread element and its children
even though they have the class attribute. Do CSS class-specific
selectors only apply to HTML elements? If I replace the xml element
names with 'div' the CSS styles apply correctly.

How can I make the CSS apply to XML elements with class atributes?

Thanks.

3.XSLT: Confusion over adding attributes with xml:element and xml:attribute

4.[XSLT] could not apply "apply-templates"

5.Making sure an Element Group contains elements with either two attributes or one attribute

6. Query : Number of Attributes under an element & atleast 1 occurence of element/Attribute

7. XSLT returning '' is an invalid QName when converting Attributes to Elements

8. XSLT to Remove Elements with Specific Attributes?



Return to xml

 

Who is online

Users browsing this forum: No registered users and 61 guest