XML matches

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    XML matches

    what a pun........

    well, back to my question. can anyone confirm that the match attribute of <xsl:template > chokes on XPaths with conditions, like
    <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
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    ? 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']"

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      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
      Code:
      // xml headers
      <xsl:stylesheet [...]>
      // xsl processing options
      
      <xsl:template match="//element[@attr = 'value']">
      // this is the only template
      // do frenzy stuff with the node
      </xsl:template>
      
      </xsl:stylesheet>
      FF gives an "invalid xpath" error

      Dormi

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Still having problems recreating it. Using xml:
        [code=xml]
        <?xml version="1.0"?>
        <?xml-stylesheet type="text/xsl" href="test.xsl" ?>
        <!-- this is a test document -->
        <document>
        <!-- test comment -->
        <x name="value">x</x>
        <y name="value">y</y>
        <z name="value">z</z>
        <abc>
        <def>def</def>
        </abc>
        <z noname="z">p</z>
        <z name="q">q</z>
        </document>
        [/code]

        xsl:
        [code=xml]
        <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
        <!-- set the output properties -->
        <xsl:output method="html"/>
        <xsl:template match="/*">
        <html>
        <head/>
        <body>
        <xsl:apply-templates/>
        </body>
        </html>
        </xsl:template>
        <xsl:template match="*">
        <div>
        <xsl:value-of select="'text'"/>
        <xsl:apply-templates/>
        </div>
        </xsl:template>
        <xsl:template match="//z[@name='value']">
        <div>
        <xsl:value-of select="'found element'"/>
        <xsl:apply-templates/>
        </div>
        </xsl:template>
        </xsl:stylesheet>
        [/code]
        Does this produce the error on your side?

        Comment

        Working...