|
Subject: Re: [xsl] match and not match using If From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 17 Sep 2016 17:36:15 -0000 |
One issue is probably this line:
> <xsl:variable name="aN" select="no"/>
>
You probably expect the variable $aN to have the value "no" but you are
selecting an element named "no" as a child of the current context, which is
very likely not present, so the value will be an empty sequence.
So you probably want:
> <xsl:variable name="aN" select="'no'"/>
For this kind of issue I like to use messages to check what's going on an in
particular verify my assumptions, e.g.:
<xsl:message> + [DEBUG] $an="<xsl:value-of select="$aN"/>"</xsl:message>
("+ [DEBUG] "is just my convention for formatting messages).
This is also a case where using @as would have revealed your error:
> <xsl:variable name="aN" select="no" as="xs:string"/>
This will produce a runtime error if there is no <no> element because an
empty string is not a valid value.
Cheers,
Eliot
--
Eliot Kimber
http://contrext.com
From: "Rahul Singh rahulsinghindia15@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Reply-To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Date: Saturday, September 17, 2016 at 10:44 AM
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] match and not match using If
> I have created positive and negative XSLTs with below codes with match and not
> match if, but not working:
>
> 1. This was when $tranFile/objects/Contact[ID__c = $aN] then need all data
> with corresponding <contactID> in each record:
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
> <xsl:strip-space elements="*"/>
> <xsl:param name="tranFile" select="document('new5.xml')"/>
> <xsl:template match="Informations">
> <Informations>
> <xsl:for-each select="Information">
> <xsl:variable name="aN" select="no"/>
> <xsl:if test="$tranFile/objects/Contact[ID__c = $aN]">
> <xsl:copy>
> <contactID><xsl:value-of
> select="$tranFile/objects/Contact/Id"/></contactID>
> <xsl:apply-templates/>
> </xsl:copy>
> </xsl:if>
> </xsl:for-each>
> </Informations>
> </xsl:template>
> <xsl:template match="@* | node()">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()"/>
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
>
> 2. And, same i have tested with negating code when
> $tranFile/objects/Contact[ID_c!= $aN] :
>
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
> <xsl:strip-space elements="*"/>
> <xsl:param name="tranFile" select="document('new5.xml')"/>
> <xsl:template match="Informations">
> <xsl:choose>
> <xsl:when test="$tranFile/objects = ''">
> <Informations>
> <xsl:copy-of select="Information"/>
> </Informations>
> </xsl:when>
> <xsl:when test="$tranFile/objects! = ''">
> <Informations>
> <xsl:for-each select="Information">
> <xsl:variable name="aN" select="no"/>
> <xsl:if test="not($tranFile/objects/Contact[ID_c=
> $aN])">
> <xsl:copy>
> <xsl:apply-templates select="."/>
> </xsl:copy>
> </xsl:if>
> </xsl:for-each>
> </Informations>
> </xsl:when>
> </xsl:choose>
> </xsl:template>
> <xsl:template match="@* | node()">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()"/>
> </xsl:copy>
> </xsl:template>
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/1278982> (by
email <> )
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] match and not match using If, Rahul Singh rahulsin | Thread | [xsl] Compare 2 XML and get Id from, Rahul Singh rahulsin |
| [xsl] match and not match using If, Rahul Singh rahulsin | Date | [xsl] Compare 2 XML and get Id from, Rahul Singh rahulsin |
| Month |