This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Building attributes using another template, context node?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] Building attributes using another template, context node?
- From: Jarno dot Elovirta at nokia dot com
- Date: Thu, 25 Oct 2001 12:50:04 +0300
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hip hei!
> I would really appreciate some help on this one :-)
> Suppose I have the following:
>
> <html:table cellspacing="0" cellpadding="0" xed:nodeType="element"
> xmlns:xed="http://www.foo.org/foo/">
html namespace declaration is missing.
> <html:tr>
> <html:td class="elemType">
> <html:button class="shown"/>
> <html:p
> class="elemNameTextArea">xsl:stylesheet</html:p>
> </html:td>
> <html:td class="childHolder">
> <html:div class="hide">
> <html:table cellspacing="0"
> cellpadding="0" xed:nodeType="attribute">
> <html:tr>
> <html:td
> class="attrType">
> <html:button
> class="hidden"/>
> <html:p
> class="elemAttrTextArea">version</html:p>
> </html:td>
> <html:td>
> <html:p
> class="xedValue" xed:areaType="attrValue">1.0</html:p>
> </html:td>
> </html:tr>
> </html:table>
> </html:div>
> </html:td>
> </html:tr>
> </html:table>
>
> I have a template that matches the outer table with the
> xed:nodeType="element" attribute-value pair. I use it to output an
> element from the html:p in it's first TD.
> Now, the problem. I am trying to construct the attribute of that
> element, using the inner table (the one with the
> xed:nodeType="attribute"). My template for the first table is:
>
> <xsl:template match="table[@xed:nodeType='element']">
The source uses the html namespace, so you have to use non-default namespace
for html in expressions - same goes for all the other expressions below
> <xsl:element name="{tr/td[@class='elemType']/p/text()}"
> xml:space="preserve">
xml:space here makes the indentation whitespace part of the content of the
element, and you cannot add an attribute node to an element after you've
added non-attribute nodes to it. thus, remove the whitespace before the
xsl:apply-template below
> <xsl:apply-templates
> select="tr/td[@class='childholder']/div/table" mode="scrapattrs"/>
In the source the value of the class attribute is childHolder, = does a
case-sensitive comparison on strings.
> <xsl:apply-templates/>
> </xsl:element>
> </xsl:template>
>
> This is a really messed up version of the second template...
>
> <xsl:template name="scrapattrs" mode="scrapattrs"
> match="table[@xed:nodeType='attribute']">
> <xsl:attribute name="{tr/td[@class='attrType']/p/text()}">
> <xsl:value-of select="tr/td/p[@areaType='attrValue']/text()"/>
Here add the html namespace prefixes, but areaType attribute is also on
non-null namespace in your source.
> </xsl:attribute>
> </xsl:template>
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list