Filtering on locations in XPath

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Jessel

    Filtering on locations in XPath

    All,

    I have an rss feed:

    <rss>
    <channel>

    <item>
    <title>
    some title
    </title>
    <link>
    some link
    </link>
    <description>
    some description
    </description>
    </item>


    <item>
    <title>
    my
    </title>
    <link>
    some link
    </link>
    <description>
    test
    </description>
    </item>

    <webMaster>benj essel@hotmail.c om</webMaster>
    </channel>
    </rss>

    How could I write an xPath statement that would return me all my data
    apart from <item> clauses that don't meed a specific critera?

    I'd like the output to be:




    I've tried

    "//item[( contains(title, 'my') or contains(descri ption,'test') )]"
    hoping that it would return:




    <rss>
    <channel>
    <item>
    <title>
    my
    </title>
    <link>
    some link
    </link>
    <description>
    test
    </description>
    </item>
    <webMaster>benj essel@hotmail.c om</webMaster>
    </channel>
    </rss>

    However it only returns the matching <item>.

    I've tried reading trhought the specification, but I really need a
    real-world example to help me!

    Thanks,

    Ben
  • Richard Tobin

    #2
    Re: Filtering on locations in XPath

    In article <2535a6fa.04072 70400.1689ef82@ posting.google. com>,
    Ben Jessel <ben.jessel@mor pheme.co.uk> wrote:
    [color=blue]
    >How could I write an xPath statement that would return me all my data
    >apart from <item> clauses that don't meed a specific critera?[/color]

    You can't. XPath can only return structures that are present in the
    input, and you want a modified version of the input.

    You could use a stylesheet to do it.

    -- Richard

    Comment

    • Ben Jessel

      #3
      Re: Filtering on locations in XPath

      > You can't. XPath can only return structures that are present in the[color=blue]
      > input, and you want a modified version of the input.[/color]

      Without wanting someone else to do my work for me ( :-) ) could
      someone come up with a sample stylesheet that gets me some of the way
      to where I want to be with this?
      Thanks,

      Ben

      Comment

      • Graham Shaw

        #4
        Re: Filtering on locations in XPath

        Hi Ben,

        not perfect but the output matches what you want and you can probably use it
        as a starter

        Graham

        <?xml version="1.0" encoding="iso-8859-1"?>
        <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
        version="1.0">
        <xsl:template match="/">
        <xsl:element name="rss">
        <xsl:element name="channel">
        <xsl:for-each select="/rss/channel/item">
        <xsl:if test="current()[contains(title, 'my') or
        contains(descri ption,'test')]">
        <xsl:element name="item">
        <xsl:element name="title">
        <xsl:value-of select="title"/>
        </xsl:element>
        <xsl:element name="link">
        <xsl:value-of select="link"/>
        </xsl:element>
        <xsl:element name="descripti on">
        <xsl:value-of select="descrip tion"/>
        </xsl:element>
        </xsl:element>
        </xsl:if>
        </xsl:for-each>
        <xsl:for-each select="/rss/channel/webMaster">
        <xsl:element name="webMaster ">
        <xsl:value-of select="."/>
        </xsl:element>
        </xsl:for-each>
        </xsl:element>
        </xsl:element>
        </xsl:template>
        </xsl:stylesheet>
        "Ben Jessel" <ben.jessel@mor pheme.co.uk> wrote in message
        news:2535a6fa.0 407280333.33633 edf@posting.goo gle.com...[color=blue][color=green]
        > > You can't. XPath can only return structures that are present in the
        > > input, and you want a modified version of the input.[/color]
        >
        > Without wanting someone else to do my work for me ( :-) ) could
        > someone come up with a sample stylesheet that gets me some of the way
        > to where I want to be with this?
        > Thanks,
        >
        > Ben[/color]


        Comment

        • Ben Jessel

          #5
          Re: Filtering on locations in XPath

          "Graham Shaw" <Graham@somewhe re.com> wrote in message news:<ckSNc.530 $YG3.476@newsfe 1-gui.ntli.net>.. .[color=blue]
          > Hi Ben,
          >
          > not perfect but the output matches what you want and you can probably use it
          > as a starter[/color]

          wow! thanks!


          Ben

          Comment

          Working...