Loading ...
Sorry, an error occurred while loading the content.

RE: [XSL-FO] Help: XPath expression

Expand Messages
  • Jeffrey A. Stewart
    Anders, If you use the selectNodes method more like this: objNodes = objDOM.selectNodes( //para ) And then reference each node like: objNode.text You should
    Message 1 of 6 , Dec 26, 2002
    • 0 Attachment
      Anders,

      If you use the selectNodes method more like this:

      objNodes = objDOM.selectNodes("//para")

      And then reference each node like:

      objNode.text

      You should get the content of the <para> tag the way you wish...

      Jeff Stewart
      Technical Director
      Trekk Cross-Media Communications



      -----Original Message-----
      From: Anders Svensson [mailto:asn@...]
      Sent: Thursday, December 26, 2002 12:12 PM
      To: XSL-FO@yahoogroups.com
      Subject: RE: [XSL-FO] Help: XPath expression

      Ok, thanks, Ken. I'll post the question there. I'm afraid your answer
      was a little beyond my reach... I consider myself quite a beginner with
      regard to XML so far... But what I'm trying to do is to accomplish this
      in VB and the DOM. Like I said, I'll post this on the other list if
      you'd be so kind as to help me out further there:
      Let me expand on the question a bit to clarify what I want to do: I
      found out that I could use the xml property of the DOMDocument object to
      output the xml content of the element. This seems like a way to go, but
      then I need to be able to get the contents of the para elements so that
      I get the text and the <italic> elements... When I use the xml property
      right now I get the entire thing as xml, i.e." <para>bla, bla,
      bla..<italic> bla, bla</italic>bla, bla</para>". What I want is: "bla,
      bla, bla..<italic> bla, bla</italic>bla, bla"

      Below I have used the Text property because it gets the right text at
      least. But I've tried replacing this with the xml property, getting the
      results described above.

      Here's the code snippet used:
      ==============================================================
      'FILL NODELIST:
      objXMLDOM.setProperty "SelectionLanguage", "XPath"
      Set objNodes = objXMLDOM.selectNodes("//*[child::text() and
      not(preceding-sibling::text() or following-sibling::text())]")

      '==============================================================
      'CREATE ID ATTRIBUTES FOR ALL SEGMENTS IN NODELIST:
      i = 0
      For Each objNode In objNodes
      i = i + 1
      Set idAttribute = objXMLDOM.createAttribute("segmentID")
      idAttribute.nodeValue = i
      objNode.Attributes.setNamedItem idAttribute
      Next objNode

      '==============================================================
      'FILL RECORDSET:
      For Each objNode In objNodes
      With rsNames
      .AddNew
      rsNames.Fields("segmentID") =
      objNode.Attributes.getNamedItem("segmentID").nodeValue

      rsNames.Fields("sourceText") = objNode.Text 'This is used now,
      because it works to get the correct text parts out at least, but
      naturally, the <strong> and <italic> bits are not included here. That's
      where the xml property would come in...
      .Update
      .MoveFirst
      End With
      Next


      Regards.

      Anders

      -----Original Message-----
      From: G. Ken Holman [mailto:gkholman@...]
      Sent: Thu 12/26/2002 6:14 PM
      To: XSL-FO@yahoogroups.com
      Cc:
      Subject: Re: [XSL-FO] Help: XPath expression



      XSLT and XPath questions would be better posted to the following
      list:

      http://www.mulberrytech.com/xsl/xsl-list

      There are a number of subscribers who would enthusiastically
      respond to
      such questions.

      There is also an *excellent* FAQ at:

      http://www.dpawson.co.uk

      At 2002-12-26 15:35 +0100, Anders Svensson wrote:
      >This isn't really an FO question, but I know most XML wizards
      are here, so
      >I'm hoping to get some help with this. I need to find the right
      Xpath
      >expression to select nodes containing elements with text, but
      to somehow
      >make internal tags, such as <strong> and <italic> and whatever
      they could
      >be, not be selected separately, but rather as a part of their
      parent
      >elements (para in the example below).

      If I've understood your question, then when I need to do this I
      use the
      identity transform in a separate mode ... an example is below.

      I hope this helps.

      .................. Ken


      T:\ftemp>type anders.xml
      <?xml version="1.0" encoding="iso-8859-1"?>
      <Desc>

      <para>The company was established in Vereno, in 1995 and is
      privately held.
      <italic>Nanonull </italic>has been actively involved in
      developing
      nanoelectronic software technologies since 1996 and released the
      first
      version of its products in February 1999.</para>

      <para>

      <strong>Due to the fact </strong>that nanoelectronic software
      components
      are so small that <strong>nobody can see </strong>it the company
      is not
      well known to the public.</para>

      </Desc>
      T:\ftemp>type anders.xsl
      <?xml version="1.0" encoding="iso-8859-1"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">

      <xsl:template match="Desc">
      <result>
      <xsl:apply-templates/>
      </result>
      </xsl:template>

      <xsl:template match="para">
      <p>
      <xsl:apply-templates mode="preserve-this-for-Anders"/>
      </p>
      </xsl:template>

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

      </xsl:stylesheet>

      T:\ftemp>saxon anders.xml anders.xsl
      <?xml version="1.0" encoding="utf-8"?><result>

      <p>The company was established in Vereno, in 1995 and is
      privately held.
      <italic>Nanonull </italic>has been actively involved in
      developing
      nanoelectronic software technologies since 1996 and released the
      first
      version of its products in February 1999.</p>

      <p>

      <strong>Due to the fact </strong>that nanoelectronic software
      components
      are so small that <strong>nobody can see </strong>it the company
      is not
      well known to the public.</p>

      </result>
      T:\ftemp>


      --
      Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO:
      - North America: Feb 3 - Feb 7,2003

      G. Ken Holman mailto:gkholman@...
      Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
      Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
      ISBN 0-13-065196-6 Definitive XSLT and XPath
      ISBN 0-13-140374-5 Definitive XSL-FO
      ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
      ISBN 1-894049-10-1 Practical Formatting Using XSL-FO
      Next conference training: 2003-03-03,06


      To unsubscribe from this group, send an email to:
      XSL-FO-unsubscribe@egroups.com



      Your use of Yahoo! Groups is subject to
      http://docs.yahoo.com/info/terms/





      To unsubscribe from this group, send an email to:
      XSL-FO-unsubscribe@egroups.com



      Your use of Yahoo! Groups is subject to
      http://docs.yahoo.com/info/terms/
    Your message has been successfully submitted and would be delivered to recipients shortly.