Connecting Tech Pros Worldwide Forums | Help | Site Map

XML matches

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#1: Nov 23 '08
what a pun........

well, back to my question. can anyone confirm that the match attribute of <xsl:template> chokes on XPaths with conditions, like
Quote:
<xsl:template match="node()[@attr = 'value']">
it's doing that every time I try this (XSLT 1.0). has anyone found an explanation for this?

regards

PS: If you wonder, I have already figured out a workaround for me

Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Nov 26 '08

re: XML matches


? Which processor are you using?
Are you sure the node isn't getting picked up by some other less-generic template?
Since you're looking for a element node, I suggest using
"*[@attr='value']"
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#3: Nov 27 '08

re: XML matches


processors:
- for a quick test I use FF's transformiix or the "get XSL result" addon
- developer server is Mac 10.5.5 / apache 2.2.10 / libxml 2.7.2 / libxslt 1.1.24 / php 5.2.6
- production server is linux / apache / php 5.2.6 / libxml 2.6.31 / libxslt 1.1.21 (-> libxml 2.6.28)

node() was just a placeholder, I have the element's xpath there.

this problem arises if I want to pick up one single element only, like
Expand|Select|Wrap|Line Numbers
  1. // xml headers
  2. <xsl:stylesheet [...]>
  3. // xsl processing options
  4.  
  5. <xsl:template match="//element[@attr = 'value']">
  6. // this is the only template
  7. // do frenzy stuff with the node
  8. </xsl:template>
  9.  
  10. </xsl:stylesheet>
FF gives an "invalid xpath" error

Dormi
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#4: Dec 1 '08

re: XML matches


Still having problems recreating it. Using xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/xsl" href="test.xsl"?>
  3. <!-- this is a test document -->
  4. <document>
  5.     <!-- test comment -->
  6.     <x name="value">x</x>
  7.     <y name="value">y</y>
  8.     <z name="value">z</z>
  9.     <abc>
  10.         <def>def</def>
  11.     </abc>
  12.     <z noname="z">p</z>
  13.     <z name="q">q</z>
  14. </document>
  15.  
xsl:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.     <!-- set the output properties -->
  3.     <xsl:output method="html"/>
  4.     <xsl:template match="/*">
  5.         <html>
  6.             <head/>
  7.             <body>
  8.                 <xsl:apply-templates/>
  9.             </body>
  10.         </html>
  11.     </xsl:template>
  12.     <xsl:template match="*">
  13.         <div>
  14.     <xsl:value-of select="'text'"/>
  15.     <xsl:apply-templates/>
  16.         </div>
  17.     </xsl:template>
  18.     <xsl:template match="//z[@name='value']">
  19.     <div>
  20.     <xsl:value-of select="'found element'"/>
  21.     <xsl:apply-templates/>
  22.     </div>
  23.     </xsl:template>
  24. </xsl:stylesheet>
  25.  
Does this produce the error on your side?
Reply

Tags
1.0, conditions, match, template, xslt