Re: [CODE4LIB] direct descendants of a given element

2017-11-17 Thread Kyle Banerjee
On Fri, Nov 17, 2017 at 2:29 AM, Ellerbeck, Carol 
wrote:

> On the other hand, is it really a case of two affiliations, or just one?
> The University of Maryland University College (UMUC) is an American public
> not-for-profit university located in Adelphi in Prince George's County,
> Maryland
>

That might be true in this case, but that suggests the specific example
involved a data entry error assuming the other areas truly need multiple
affiliations.

If it turned out that *all* cases of multiple affiliations were the same as
you identify, an especially easy way to deal with this would be to tweak
the output so that paper appeared before the authors (or alter the DTD so
it's an attribute of presentation). The output could then be generated with
a single line command that stripped the newlines with tr and piped that
output into sed. Though doing stuff like that via regex is not very eye
pleasing even it's fast and easy.

kyle


Re: [CODE4LIB] direct descendants of a given element

2017-11-17 Thread Ellerbeck, Carol
On the other hand, is it really a case of two affiliations, or just one?  The 
University of Maryland University College (UMUC) is an American public 
not-for-profit university located in Adelphi in Prince George's County, Maryland


Cheers,


Carol

Carol A. Ellerbeck
Taxonomist & Metadata Manager
Knowledge & Library Services
Baker Library
Harvard Business School
PH: 617-495-6745



From: Code for Libraries <CODE4LIB@LISTS.CLIR.ORG> on behalf of Brian Sheppard 
<brian.shepp...@wisc.edu>
Sent: Thursday, November 16, 2017 1:56 PM
To: CODE4LIB@LISTS.CLIR.ORG
Subject: Re: [CODE4LIB] direct descendants of a given element

Yeah, those affiliations really want to be within the person element, but ...

This seems to work for me:


http://www.w3.org/1999/XSL/Transform; 
xmlns:func="http://exslt.org/functions; 
xmlns:date="http://exslt.org/dates-and-times; 
xmlns:exsl="http://exslt.org/common; version="1.0" 
exclude-result-prefixes="func exsl date xsl">
XSLT Namespace<http://www.w3.org/1999/XSL/Transform>
www.w3.org
The namespace http://www.w3.org/1999/XSL/Transform is referred to as "the XSLT 
namespace". The prefix xsl is conventionally used to refer to this namespace 
(and is so ...



  
  
  

  
  

  
  

  
  

  

  
  
  

  
  
  


  
  

  

  




> On November 16, at 11:42 AM, Eric Lease Morgan <emor...@nd.edu> wrote:
>
> How can I use XSLT to find the direct descendants of a given element with a 
> given name?
>
> I want to create a tab-delimited version of an XML file. I have the following 
> XML snippet, and notice how each of the persons in the first presentation 
> have a single affiliation, but the person of the second presentation has two 
> affiliations:
>
>  
>
>  RICHARD G. ANDERSON
>  Lindenwood University
>  AREERAT KICHKHA
>  Lindenwood University
>  Is Less More?
>
>
>  BRIAN W. SLOBODA
>  University of Maryland
>  University College
>  Inflation Policies
>
>  
>
> I want my resulting tab-delimited file to look like this:
>
>  RICHARD G. ANDERSON  Lindenwood University  Is Less More?
>  AREERAT KICHKHA  Lindenwood University  Is Less More?
>  BRIAN W. SLOBODA University of Maryland|University College  Inflation 
> Policies
>
> I have the following XSLT snippet, but my process of getting affiliations is 
> not nearly correct:
>
>  
>
>  
>   select="normalize-space(../affiliation)"/>
>   select="normalize-space(../paper)"/>
>
>  
>
> Can you offer any suggestions? What sort of XPath expression should I be 
> using to find all of the affiliation elements between person elements? 
> Something with following-sibling?

—
Brian Sheppard
UW Digital Collections Center
brian.shepp...@wisc.edu


Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Eric Lease Morgan
On Nov 16, 2017, at 2:22 PM, Kyle Banerjee  wrote:

> Are you using XSLT because you need to, or is it because your source is in
> XML? Also, do you have any environmental constraints?
> 
> The reason I ask is that converting that specific XML to the tab delimited
> output you specify looks like it would be much easier via conversion to
> JSON and filtered through jq than using XSLT.


I am using XSLT because may source is in XML. People are marking up plain text 
into XML with Oxygen. From within the Oxygen environment they can then execute 
the XSLT to create the tab-delimited files. Piping the XML to JSON (the “new 
XML”) would add complexity to the workflow. —Eric


Re: [CODE4LIB] direct descendants of a given element [resolved]

2017-11-16 Thread Eric Lease Morgan
On Nov 16, 2017, at 1:56 PM, Brian Sheppard  wrote:

> Yeah, those affiliations really want to be within the person element, but ...


Yes, Brian’s solution works quite well:

  

  

  
   

 


  
  

  

  

And I’m seriously thinking about changing my DTD so affiliations reside inside 
a person element. 

Thank you.  code4lib++

—
Eric Morgan


Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Kyle Banerjee
Howdy Eric,

Are you using XSLT because you need to, or is it because your source is in
XML? Also, do you have any environmental constraints?

The reason I ask is that converting that specific XML to the tab delimited
output you specify looks like it would be much easier via conversion to
JSON and filtered through jq than using XSLT.

kyle

On Thu, Nov 16, 2017 at 9:42 AM, Eric Lease Morgan  wrote:

> How can I use XSLT to find the direct descendants of a given element with
> a given name?
>
> I want to create a tab-delimited version of an XML file. I have the
> following XML snippet, and notice how each of the persons in the first
> presentation have a single affiliation, but the person of the second
> presentation has two affiliations:
>
>   
> 
>   RICHARD G. ANDERSON
>   Lindenwood University
>   AREERAT KICHKHA
>   Lindenwood University
>   Is Less More?
> 
> 
>   BRIAN W. SLOBODA
>   University of Maryland
>   University College
>   Inflation Policies
> 
>   
>
> I want my resulting tab-delimited file to look like this:
>
>   RICHARD G. ANDERSON  Lindenwood University  Is Less
> More?
>   AREERAT KICHKHA  Lindenwood University  Is Less
> More?
>   BRIAN W. SLOBODA University of Maryland|University College
> Inflation Policies
>
> I have the following XSLT snippet, but my process of getting affiliations
> is not nearly correct:
>
>   
> 
>   <
> xsl:text>
>   
>   
> 
>   
>
> Can you offer any suggestions? What sort of XPath expression should I be
> using to find all of the affiliation elements between person elements?
> Something with following-sibling?
>


Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Tim Thompson
Hi, Eric,

Here is more of a "push" approach (assuming you are able to use XSLT
2.0+)--which I highly recommend whenever working with XSLT.



http://www.w3.org/1999/XSL/Transform;
xmlns:xs="http://www.w3.org/2001/XMLSchema;
exclude-result-prefixes="xs" version="2.0">






























--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

www.linkedin.com/in/timathompson
timothy.thomp...@yale.edu

On Thu, Nov 16, 2017 at 1:56 PM, Brian Sheppard 
wrote:

> Yeah, those affiliations really want to be within the person element, but
> ...
>
> This seems to work for me:
>
> 
> http://www.w3.org/1999/XSL/Transform;
> xmlns:func="http://exslt.org/functions; xmlns:date="http://exslt.org/
> dates-and-times" xmlns:exsl="http://exslt.org/common; version="1.0"
> exclude-result-prefixes="func exsl date xsl">
>encoding="utf-8" indent="yes"/>
>   
>   
> 
>   
>   
> 
>   
>   
> 
>   
>   
> 
>   
> 
>   
>   
>   
> 
>   
>   
>   
> 
> 
>   
>   
> 
>   
> 
>   
> 
>
>
>
> > On November 16, at 11:42 AM, Eric Lease Morgan  wrote:
> >
> > How can I use XSLT to find the direct descendants of a given element
> with a given name?
> >
> > I want to create a tab-delimited version of an XML file. I have the
> following XML snippet, and notice how each of the persons in the first
> presentation have a single affiliation, but the person of the second
> presentation has two affiliations:
> >
> >  
> >
> >  RICHARD G. ANDERSON
> >  Lindenwood University
> >  AREERAT KICHKHA
> >  Lindenwood University
> >  Is Less More?
> >
> >
> >  BRIAN W. SLOBODA
> >  University of Maryland
> >  University College
> >  Inflation Policies
> >
> >  
> >
> > I want my resulting tab-delimited file to look like this:
> >
> >  RICHARD G. ANDERSON  Lindenwood University  Is Less
> More?
> >  AREERAT KICHKHA  Lindenwood University  Is Less
> More?
> >  BRIAN W. SLOBODA University of Maryland|University College
> Inflation Policies
> >
> > I have the following XSLT snippet, but my process of getting
> affiliations is not nearly correct:
> >
> >  
> >
> >  <
> xsl:text>
> >  
> >  
> >
> >  
> >
> > Can you offer any suggestions? What sort of XPath expression should I be
> using to find all of the affiliation elements between person elements?
> Something with following-sibling?
>
> —
> Brian Sheppard
> UW Digital Collections Center
> brian.shepp...@wisc.edu
>
>
>
>
>
>


Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Brian Sheppard
Yeah, those affiliations really want to be within the person element, but ...

This seems to work for me:


http://www.w3.org/1999/XSL/Transform; 
xmlns:func="http://exslt.org/functions; 
xmlns:date="http://exslt.org/dates-and-times; 
xmlns:exsl="http://exslt.org/common; version="1.0" 
exclude-result-prefixes="func exsl date xsl">
  
  
  

  
  

  
  

  
  

  

  
  
  

  
  
  


  
  

  

  




> On November 16, at 11:42 AM, Eric Lease Morgan  wrote:
> 
> How can I use XSLT to find the direct descendants of a given element with a 
> given name?
> 
> I want to create a tab-delimited version of an XML file. I have the following 
> XML snippet, and notice how each of the persons in the first presentation 
> have a single affiliation, but the person of the second presentation has two 
> affiliations:
> 
>  
>
>  RICHARD G. ANDERSON
>  Lindenwood University
>  AREERAT KICHKHA
>  Lindenwood University
>  Is Less More?
>
>
>  BRIAN W. SLOBODA
>  University of Maryland
>  University College
>  Inflation Policies
>
>  
> 
> I want my resulting tab-delimited file to look like this:
> 
>  RICHARD G. ANDERSON  Lindenwood University  Is Less More?
>  AREERAT KICHKHA  Lindenwood University  Is Less More?
>  BRIAN W. SLOBODA University of Maryland|University College  Inflation 
> Policies
> 
> I have the following XSLT snippet, but my process of getting affiliations is 
> not nearly correct:
> 
>  
>
>  
>   select="normalize-space(../affiliation)"/>
>   select="normalize-space(../paper)"/>
>
>  
> 
> Can you offer any suggestions? What sort of XPath expression should I be 
> using to find all of the affiliation elements between person elements? 
> Something with following-sibling? 

—
Brian Sheppard
UW Digital Collections Center
brian.shepp...@wisc.edu







Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Ashley M. Clark

Hi Eric,

Whew, this is a tangle! Getting the descendants of a given element is 
easy in XPath, and your nested  instructions should do the 
right thing. You could even combine the two instructions with this XPath:


    .//presentation//person

The difficulty you noted is that there's no hierarchy to explicitly 
connect any given person to their affiliation. For each person, you need 
to get the following elements named 'affiliation' that _do not_ occur 
after a following . This is not an easy XPath to write!


When I've run into this problem in the past, I've used a named XSLT 
template which takes the next X number of siblings and tests if they 
meet an inclusion criteria (here, "am I an ?" or 
`exists(self::affiliation)` ). Everything after the first non-match is 
thrown out.


However, this is not a method I'd recommend to anyone, because it turns 
out there's a somewhat easier method using :


   
  
  
  
  
  
    Working on 
    
     of 
    
  

  
  
  
    


I found out about this method in Michael Kay's excellent _XSLT 2.0 and 
XPath 2.0_. It forms a group of all sibling elements that occur after 
, but before the next . You can then use the 
`current-group()` function to get the sequence of elements that for sure 
are associated with this particular person, and tests on the self axis 
to narrow _those_ down to only the elements of a certain type. I added 
some special sauce with the `string-join()` function to put a '|' 
between each affiliation for a given person.


Hope this helps!

Best,
Ashley



On 11/16/17 12:42 PM, Eric Lease Morgan wrote:

How can I use XSLT to find the direct descendants of a given element with a 
given name?

I want to create a tab-delimited version of an XML file. I have the following 
XML snippet, and notice how each of the persons in the first presentation have 
a single affiliation, but the person of the second presentation has two 
affiliations:

   
 
   RICHARD G. ANDERSON
   Lindenwood University
   AREERAT KICHKHA
   Lindenwood University
   Is Less More?
 
 
   BRIAN W. SLOBODA
   University of Maryland
   University College
   Inflation Policies
 
   

I want my resulting tab-delimited file to look like this:

   RICHARD G. ANDERSON  Lindenwood University  Is Less More?
   AREERAT KICHKHA  Lindenwood University  Is Less More?
   BRIAN W. SLOBODA University of Maryland|University College  Inflation 
Policies

I have the following XSLT snippet, but my process of getting affiliations is 
not nearly correct:

   
 
   
   
   
 
   

Can you offer any suggestions? What sort of XPath expression should I be using 
to find all of the affiliation elements between person elements? Something with 
following-sibling?


--

Ashley M. Clark
XML Applications Developer
Digital Scholarship Group
Northeastern University Libraries
as.cl...@neu.edu 
(617) 373-5983


Re: [CODE4LIB] direct descendants of a given element

2017-11-16 Thread Ron Gilmour
Have you tried wrapping the affiliation bit in a for-each? Something like:

  

  
  
  |
 
  
  

  

Ron Gilmour
Web Services Librarian
Ithaca College Library


On Thu, Nov 16, 2017 at 12:42 PM, Eric Lease Morgan  wrote:

> How can I use XSLT to find the direct descendants of a given element with
> a given name?
>
> I want to create a tab-delimited version of an XML file. I have the
> following XML snippet, and notice how each of the persons in the first
> presentation have a single affiliation, but the person of the second
> presentation has two affiliations:
>
>   
> 
>   RICHARD G. ANDERSON
>   Lindenwood University
>   AREERAT KICHKHA
>   Lindenwood University
>   Is Less More?
> 
> 
>   BRIAN W. SLOBODA
>   University of Maryland
>   University College
>   Inflation Policies
> 
>   
>
> I want my resulting tab-delimited file to look like this:
>
>   RICHARD G. ANDERSON  Lindenwood University  Is Less
> More?
>   AREERAT KICHKHA  Lindenwood University  Is Less
> More?
>   BRIAN W. SLOBODA University of Maryland|University College
> Inflation Policies
>
> I have the following XSLT snippet, but my process of getting affiliations
> is not nearly correct:
>
>   
> 
>   <
> xsl:text>
>   
>   
> 
>   
>
> Can you offer any suggestions? What sort of XPath expression should I be
> using to find all of the affiliation elements between person elements?
> Something with following-sibling?
>


[CODE4LIB] direct descendants of a given element

2017-11-16 Thread Eric Lease Morgan
How can I use XSLT to find the direct descendants of a given element with a 
given name?

I want to create a tab-delimited version of an XML file. I have the following 
XML snippet, and notice how each of the persons in the first presentation have 
a single affiliation, but the person of the second presentation has two 
affiliations:

  

  RICHARD G. ANDERSON
  Lindenwood University
  AREERAT KICHKHA
  Lindenwood University
  Is Less More?


  BRIAN W. SLOBODA
  University of Maryland
  University College
  Inflation Policies

  

I want my resulting tab-delimited file to look like this:

  RICHARD G. ANDERSON  Lindenwood University  Is Less More?
  AREERAT KICHKHA  Lindenwood University  Is Less More?
  BRIAN W. SLOBODA University of Maryland|University College  Inflation 
Policies

I have the following XSLT snippet, but my process of getting affiliations is 
not nearly correct:

  

  
  
  

  

Can you offer any suggestions? What sort of XPath expression should I be using 
to find all of the affiliation elements between person elements? Something with 
following-sibling?