xsl-list
[Top] [All Lists]

RE: Test for node name and attribute value

2004-11-30 07:55:44
Still no source document, but if I apply this to the source document

<my-relation/>

I get

<?xml version="1.0"
encoding="UTF-8"?><FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO/><my-relation/>

and if I change the template rule to say match="my-relation" I get exactly
the same output.

Perhaps my-relation in your source document is actually an attribute rather
than an element?

Michael Kay
http://www.saxonica.com/ 



-----Original Message-----
From: Robert Soesemann [mailto:rsoesemann(_at_)sapient(_dot_)com] 
Sent: 30 November 2004 13:59
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Test for node name and attribute value

Sorry for not telling you everything.
Here is my whole xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
      
      <!-- Copy nodes except those affected by other templates -->
      <xsl:template match="/ | @* | node()">
         <xsl:copy>
           <xsl:apply-templates select="@* | node()"/>
         </xsl:copy>
      </xsl:template>


      <!-- Match all kiwi-relation elements  -->
      <xsl:template match="node()[name(.) =
'my-relation']"><FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO/>
         <xsl:copy>
                      <xsl:copy-of select="@*"/>              
                      
                      <!-- Get expected type of related content -->
                      <xsl:variable name="expected-type"
select="@type"/>            

                      <!-- For each <A> pointing to related content...
-->
                      <xsl:for-each select="kiwi-link">

                              <!-- Extract type of external
contentitem eighter from anchored fragment or document  -->
                              <xsl:variable name="external-type">
                                      <xsl:variable
name="external-doc" select="document(@url)"/>

                                      <xsl:choose>
                                              <xsl:when test="@anchor
!= ''">
                                                      <xsl:variable
name="anchor-name" select="@anchor"/>
                                                      <xsl:variable
name="anchor-node"  select="$external-doc//my-anchor[(_at_)name =
$anchor-name]"/>
                                                      <xsl:value-of
select="$anchor-node/ancestor::my-contentitem[1]/@type"/>
                                              </xsl:when>
                                              <xsl:otherwise>
                                                      <xsl:value-of
select="//my-contentitem/@type"/>
                                              </xsl:otherwise>
                                      </xsl:choose>
                              </xsl:variable>


                              <!-- 
                                      Include my-link tag when types
match, 
                                      otherwise add my-error tag
                               -->
                              <xsl:choose>
                                      <xsl:when test="$expected-type =
$external-type">
                                              <kiwi-link url="{(_at_)href}"
/>
                                      </xsl:when>

                                      <xsl:otherwise>
                                              <my-error>
                                                      Unable to
resolve relation to file '<xsl:value-of select="@href"/>'.
                                                      Expected type:
<xsl:value-of select="$expected-type"/>  | 
                                                      Found type:
<xsl:value-of select="$external-type"/>
                                              </my-error>
                                      </xsl:otherwise>
                              </xsl:choose>
                              
                      </xsl:for-each>
          </xsl:copy>
      </xsl:template>

</xsl:stylesheet>

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Dienstag, 30. November 2004 14:51
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Test for node name and attribute value


Thanks for you reply.
I don't know why but node matches don't work when I use the simple
syntax:

my-relation

instead of

node()[name(.)='my-relation'

Is there something wron with my xsl transformer?

Given that you have been asking fairly elementary XPath questions, it
seems more likely that the error is on your side. Show us a 
full example
of what you are doing, and we'll tell you where it's wrong.

Michael Kay
http://www.saxonica.com/ 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>