backwards contains()???

D

Dave

i must be going cross eyed after looking at this for so long... given the
source xml doc:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<table tagname="tablename1">
<tablename1 rownum="0">
<field1>1</field1>
</tablename1>
</table>
<table tagname="tablename2">
<tablename2 rownum="0">
<field1>11</field1>
</tablename2>
</table>
</root>

and the transform:

<xsl:template match="@*|node()">
<xsl:if test="contains(@tagname,tablename1) ">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

why does it give me tablename2 in the output instead of tablename1??
it does the same thing with both msxsl and access's external data import
transform.
 
D

Dimitre Novatchev

Dave said:
i must be going cross eyed after looking at this for so long... given the
source xml doc:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<table tagname="tablename1">
<tablename1 rownum="0">
<field1>1</field1>
</tablename1>
</table>
<table tagname="tablename2">
<tablename2 rownum="0">
<field1>11</field1>
</tablename2>
</table>
</root>

and the transform:

<xsl:template match="@*|node()">
<xsl:if test="contains(@tagname,tablename1) ">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

why does it give me tablename2 in the output instead of tablename1??
it does the same thing with both msxsl and access's external data import
transform.


There are a number of errors in the code, one of not quoting the string
(2nd) argument of contains(), making it thus the *element* with name
tablename1.

The error that is even worse is the attempt to alter the identity rule...
o:(

The proper, well-established way to do this, which is a classic XSLT design
pattern is to override the identity rule with another rule. This code is
presented below:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:blush:utput omit-xml-declaration="yes" indent="yes"/>


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="table[not(@tagname = 'tablename1')]"/>

</xsl:stylesheet>

Cheers,
Dimitre Novatchev
 
D

Dave

Dimitre Novatchev said:
Dave said:
i must be going cross eyed after looking at this for so long... given the
source xml doc:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<table tagname="tablename1">
<tablename1 rownum="0">
<field1>1</field1>
</tablename1>
</table>
<table tagname="tablename2">
<tablename2 rownum="0">
<field1>11</field1>
</tablename2>
</table>
</root>

and the transform:

<xsl:template match="@*|node()">
<xsl:if test="contains(@tagname,tablename1) ">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

why does it give me tablename2 in the output instead of tablename1??
it does the same thing with both msxsl and access's external data import
transform.


There are a number of errors in the code, one of not quoting the string
(2nd) argument of contains(), making it thus the *element* with name
tablename1.

The error that is even worse is the attempt to alter the identity rule...
o:(

The proper, well-established way to do this, which is a classic XSLT
design pattern is to override the identity rule with another rule. This
code is presented below:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:blush:utput omit-xml-declaration="yes" indent="yes"/>


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="table[not(@tagname = 'tablename1')]"/>

</xsl:stylesheet>

Cheers,
Dimitre Novatchev
thanks, works great
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top