Correct XPath expression to get title nexted in xhtml <span>'s

Hi, Whilst working on xhtml --> xml xslt I've run into a blocker when trying to specify the XPath expression to get a title embedded within nested xhtml <span>'s. A snippet from the body of my xhtml is below: <body> <a name="gen01" id="gen01"></a><div id="content"> <div id="page1" class="page css-gen1"> <div style="width:150pt;height:12pt;left:34pt;top:33pt"> <div style="top:9pt"> <span class="css-gen2"> <span>domestic | general | application | 2010</span> </span> </div> </div> <div style="width:65pt;height:61pt;left:34pt;top:69pt"> <div style="top:11pt"> <span class="css-gen3"> <span class="css-gen4">Application</span> </span> </div> ... And so far my xsl looks like <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ukm="http://www.legislation.gov.uk/namespaces/metadata" xmlns:ukl="http://www.legislation.gov.uk/namespaces/legislation" xmlns:dc="http://purl.org/dc/elements/1.1" xmlns:dct="http://purl.org/dc/terms" xmlns:atom="http://www.w3.org2005/Atom" xmlns:html="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.legislation.gov.uk/namespaces/legislation http://www.legislation.gov.uk/schema/schemaLegislationBase-v1-0.xsd" xml:base="http://www.legislation.gov.uk/id/ssi/2011/120" exclude-result-prefixes="xs xd" version="2.0" > <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xd:doc scope="stylesheet"> <xd:desc> <xd:p><xd:b>Created on:</xd:b> Feb 21, 2012</xd:p> <xd:p><xd:b>Author:</xd:b> lewismc</xd:p> <xd:p></xd:p> </xd:desc> </xd:doc> <xsl:template match="/"> <Legislation> <xsl:apply-templates select="html:html"/> </Legislation> </xsl:template> <xsl:template match="html:html/html:body"> <Secondary> <Body DocumentURI="" IdURI="" NumberOfProvisions=""> <P1group> <Title> <xsl:value-of select="html:a/html:div/html:div/html:div/html:span/html:span"/> </Title> I know this looks ridiculous, (I've tried many XPath combinations) so apologies in advance for anyone that either laughing or crying whilst viewing this. Basically, I would like to get as output <Secondary> <Body NumberOfProvisions="" IdURI="" DocumentURI=""> <P1group> <Title>domestic | general | application | 2010</Title> Anyone that could give me a pointer would make me very happy. Kind Regards and thank you in advance. Lewis Glasgow Caledonian University is a registered Scottish charity, number SC021474 Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en... Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,e...

Hi, Please note that the a element is empty and all the content is inside a div which is the following sibling of the a element. So your XPath should look something like <xsl:value-of select="html:div/html:div/html:div/html:div/html:span/html:span"/> However, please note that this will select also the second span element as that matches the above expression. To match only the first you may want <xsl:value-of select="(html:div/html:div/html:div/html:div/html:span/html:span)[1]"/> If you set xpath-default-namespace="http://www.w3.org/1999/xhtml" in your XSLT then you will not need html: to qualify the name tests, as they will be taken to be in the namespace specified by xpath-default-namespace. This will help you because you can go in oXygen, on the element you want to refer and use the "Copy XPath" action from the contextual menu, that will give you in this case /html/body[1]/div[1]/div[1]/div[1]/div[1]/span[1]/span[1] which will select exactly that element. Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 2/27/12 3:51 PM, McGibbney, Lewis John wrote:
Hi,
Whilst working on xhtml --> xml xslt I've run into a blocker when trying to specify the XPath expression to get a title embedded within nested xhtml<span>'s. A snippet from the body of my xhtml is below:
<body> <a name="gen01" id="gen01"></a><div id="content"> <div id="page1" class="page css-gen1"> <div style="width:150pt;height:12pt;left:34pt;top:33pt"> <div style="top:9pt"> <span class="css-gen2"> <span>domestic | general | application | 2010</span> </span> </div> </div> <div style="width:65pt;height:61pt;left:34pt;top:69pt"> <div style="top:11pt"> <span class="css-gen3"> <span class="css-gen4">Application</span> </span> </div> ...
And so far my xsl looks like
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ukm="http://www.legislation.gov.uk/namespaces/metadata" xmlns:ukl="http://www.legislation.gov.uk/namespaces/legislation" xmlns:dc="http://purl.org/dc/elements/1.1" xmlns:dct="http://purl.org/dc/terms" xmlns:atom="http://www.w3.org2005/Atom" xmlns:html="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.legislation.gov.uk/namespaces/legislation http://www.legislation.gov.uk/schema/schemaLegislationBase-v1-0.xsd" xml:base="http://www.legislation.gov.uk/id/ssi/2011/120" exclude-result-prefixes="xs xd" version="2.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xd:doc scope="stylesheet"> <xd:desc> <xd:p><xd:b>Created on:</xd:b> Feb 21, 2012</xd:p> <xd:p><xd:b>Author:</xd:b> lewismc</xd:p> <xd:p></xd:p> </xd:desc> </xd:doc> <xsl:template match="/"> <Legislation> <xsl:apply-templates select="html:html"/> </Legislation> </xsl:template> <xsl:template match="html:html/html:body"> <Secondary> <Body DocumentURI="" IdURI="" NumberOfProvisions=""> <P1group> <Title> <xsl:value-of select="html:a/html:div/html:div/html:div/html:span/html:span"/> </Title>
I know this looks ridiculous, (I've tried many XPath combinations) so apologies in advance for anyone that either laughing or crying whilst viewing this. Basically, I would like to get as output
<Secondary> <Body NumberOfProvisions="" IdURI="" DocumentURI=""> <P1group> <Title>domestic | general | application | 2010</Title>
Anyone that could give me a pointer would make me very happy.
Kind Regards and thank you in advance.
Lewis
Glasgow Caledonian University is a registered Scottish charity, number SC021474
Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en...
Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,e... _______________________________________________ oXygen-user mailing list oXygen-user@oxygenxml.com http://www.oxygenxml.com/mailman/listinfo/oxygen-user

Hi George, Excellent explaination, thank you kindly for your direction. Best Lewis ________________________________________ From: George Cristian Bina [george@oxygenxml.com] Sent: 27 February 2012 14:08 To: McGibbney, Lewis John Cc: oxygen-user@oxygenxml.com Subject: Re: [oXygen-user] Correct XPath expression to get title nexted in xhtml <span>'s Hi, Please note that the a element is empty and all the content is inside a div which is the following sibling of the a element. So your XPath should look something like <xsl:value-of select="html:div/html:div/html:div/html:div/html:span/html:span"/> However, please note that this will select also the second span element as that matches the above expression. To match only the first you may want <xsl:value-of select="(html:div/html:div/html:div/html:div/html:span/html:span)[1]"/> If you set xpath-default-namespace="http://www.w3.org/1999/xhtml" in your XSLT then you will not need html: to qualify the name tests, as they will be taken to be in the namespace specified by xpath-default-namespace. This will help you because you can go in oXygen, on the element you want to refer and use the "Copy XPath" action from the contextual menu, that will give you in this case /html/body[1]/div[1]/div[1]/div[1]/div[1]/span[1]/span[1] which will select exactly that element. Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 2/27/12 3:51 PM, McGibbney, Lewis John wrote:
Hi,
Whilst working on xhtml --> xml xslt I've run into a blocker when trying to specify the XPath expression to get a title embedded within nested xhtml<span>'s. A snippet from the body of my xhtml is below:
<body> <a name="gen01" id="gen01"></a><div id="content"> <div id="page1" class="page css-gen1"> <div style="width:150pt;height:12pt;left:34pt;top:33pt"> <div style="top:9pt"> <span class="css-gen2"> <span>domestic | general | application | 2010</span> </span> </div> </div> <div style="width:65pt;height:61pt;left:34pt;top:69pt"> <div style="top:11pt"> <span class="css-gen3"> <span class="css-gen4">Application</span> </span> </div> ...
And so far my xsl looks like
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ukm="http://www.legislation.gov.uk/namespaces/metadata" xmlns:ukl="http://www.legislation.gov.uk/namespaces/legislation" xmlns:dc="http://purl.org/dc/elements/1.1" xmlns:dct="http://purl.org/dc/terms" xmlns:atom="http://www.w3.org2005/Atom" xmlns:html="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.legislation.gov.uk/namespaces/legislation http://www.legislation.gov.uk/schema/schemaLegislationBase-v1-0.xsd" xml:base="http://www.legislation.gov.uk/id/ssi/2011/120" exclude-result-prefixes="xs xd" version="2.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xd:doc scope="stylesheet"> <xd:desc> <xd:p><xd:b>Created on:</xd:b> Feb 21, 2012</xd:p> <xd:p><xd:b>Author:</xd:b> lewismc</xd:p> <xd:p></xd:p> </xd:desc> </xd:doc> <xsl:template match="/"> <Legislation> <xsl:apply-templates select="html:html"/> </Legislation> </xsl:template> <xsl:template match="html:html/html:body"> <Secondary> <Body DocumentURI="" IdURI="" NumberOfProvisions=""> <P1group> <Title> <xsl:value-of select="html:a/html:div/html:div/html:div/html:span/html:span"/> </Title>
I know this looks ridiculous, (I've tried many XPath combinations) so apologies in advance for anyone that either laughing or crying whilst viewing this. Basically, I would like to get as output
<Secondary> <Body NumberOfProvisions="" IdURI="" DocumentURI=""> <P1group> <Title>domestic | general | application | 2010</Title>
Anyone that could give me a pointer would make me very happy.
Kind Regards and thank you in advance.
Lewis
Glasgow Caledonian University is a registered Scottish charity, number SC021474
Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en...
Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,e... _______________________________________________ oXygen-user mailing list oXygen-user@oxygenxml.com http://www.oxygenxml.com/mailman/listinfo/oxygen-user Email has been scanned for viruses by Altman Technologies' email management service - www.altman.co.uk/emailsystems
Glasgow Caledonian University is a registered Scottish charity, number SC021474 Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en... Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners. http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,e...
participants (2)
-
George Cristian Bina
-
McGibbney, Lewis John