Results 1 to 12 of 12
  1. #1
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printing XPath from Word (2003 sp1)

    If this is the wrong forum I apologize, but since there is no XML forum... We're using XML-ized Word docs and using XPath to tie them into our software. We have a nifty custom tool for mapping XPath. But there is no way to print XPath code from documents. In Word, the XPath can be viewed in the attributes of the XML tags. I can also view (but not print) XPath for individual docs from our mapping tool. Since our XPath is sometimes quite complex, I'd like to see & compare printed copies of XPath from many documents. Also, it would be preferable to be able to print the corresponding XML as well.

    I have googled for some kind of tool to do this but no luck.

    Any help would be greatly appreciated. Also, if you know of a more appropriate place for me to post this question, please let me know.

    Thanks!
    BarB

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    I'm a bit unclear about your request. Please elaborate on what you mean by "mapping xpath". I'm also quite confused by, "In Word, the XPath can be viewed in the attributes of the XML tags".

    Are you referring to WordprocessingML?

  3. #3
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Andrew, if you right-click on the XML tag in a Word XML document, you see the Attributes option. When you click on it, a dialog box is opened up showing the attributes (or XPath) for the tag. See the attached images. Hope this helps clarify.
    Attached Images Attached Images

  4. #4
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Second screenshot attached.
    Attached Images Attached Images

  5. #5
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Ah, thank you very much for the screenshots, that helped quite a bit.

  6. #6
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Hmm. As best I can tell, you're viewing an XSLT stylesheet from within Word, which is why the value of the "select" attribute in the "for-each" element is an xpath expression. I had thought perhaps Word was dynamically generating the xpath for elements/attributes on the fly, but it just displays the value of the attribute, which in this case is an xpath expression.

    Are you saying you'd like to view all of the xpath expressions used in the xslt stylesheet you're viewing? Have you considered viewing the XSLT stylesheet from a plain text editor rather than from Word?

  7. #7
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    If you just want to do things like list all the xpaths matched by for-each elements in an xslt stylesheet, I'd recommend xmlstarlet, a free command-line utility for processing/querying xml documents, available at: http://xmlstar.sourceforge.net/.

    For example, if you had a stylesheet "foo.xsl", and you wanted a list of all the xpaths used by for-each elements, you'd use the following command:
    <pre>xml sel -t -m "//xsl:for-each/@select" -v "." -n foo.xsl</pre>


    Not sure how comfortable you are with xml/xslt, but I've found xmlstarlet to be a lifesaver.

  8. #8
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Thanks Andrew. I'll go look at xmlstar. (I should be getting XML Spy one of these days, when they give me a license)

    I'm actually trying to look at the xpath in Word .xml documents, not style sheets. But I'm sure it doesn't make a difference in terms of what I'm trying to do. I tried opening one of them in a text editor (EditPlus), but the xpath isn't there. (I don't get that!)

    I want to print a list of ALL XPath for each document I'm working on (over 100). Different developers worked on them, and I want to compare how they constructed their xpath. And learn from it. And reuse it. Also, it looks like I'll be taking over the xpath mapping.

    So I'll go check out XMLstar.

    Thanks!
    -BarB

  9. #9
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Hi Barb,

    The "Word .xml" documents you're looking at are xslt stylesheets. (or at least also have elements named "for-each" with attributes named "select" which have values that are xpath expressions). Can you post one of these "Word .xml" documents?

  10. #10
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Andrew, I can't attach an XML file, so I tried saving it as a doc. I still see the XML tags. Don't know if you will on this end! Anyway it's a truncated version of a very simple form.
    Attached Files Attached Files

  11. #11
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Hi Barb,

    Thanks for posting the sample, it really helped me understand the files you're working with. Not XSLT, but certainly influenced by it!

    I've attached a zip file containing two documents: "list-xpaths.xsl" and "xpaths.txt". I created the second file, "xpaths.txt", by applying the first as a transformation to the document you posted.

    To do the same, save the "list-xpaths.xsl" file to your computer, and open up one of your docs. Choose Save As XML, and then check the box marked "apply transform". Press the button labeld "transform", and navigate to the "list-xpaths.xsl" file. In the File Name box, type "docxpaths.txt" (including the quotes, or you'll get an .xml extension), and finally press "Save".

    Note that the title bar of the open doc will now (wrongly) display "docxpaths.txt". Just close the open doc, then choose File -> Open, and open the docxpaths.txt file you just created.

    This is just a very simple listing of the values of the "test" and "select" attributes. It'd certainly be possible to actually format this stuff out as an actual Word doc, perhaps in a table or something. For more on generating WordprocessingML with XSLT, see chapter 10 of my book (can't resist a chance to drop in a plug).
    Attached Files Attached Files

  12. #12
    Lounger
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing XPath from Word (2003 sp1)

    Far out Andrew! THANK YOU THANK YOU THANK YOU. <breathless>

    I tried it on one of the bigger forms and generated a .txt file with over 150 lines of xpath!

    I see there is MUCH for me to learn. I'll have to read more about xslt and, oh yeah, maybe even pick up a copy of your book (for which i wanted an excuse to buy anyway), and get to town.

    Thanks so much for spending time on this. You have run a transformation on me.

    -Barbie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •