XPath expressions having namespaces

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

I have the following xml file and need some tips on xpath queries to
fetch the data.

I think I'm not handling namespaces correctly.

Here is xml file :


<?xml version="1.0" encoding="UTF-8"?>

<epi:component build-version="Gold"
component-id="sss0005style0001"
component-type="Grids"
description="Grid that has 3 columns."
epi-build="105"
epi-version="7.1"
major-version="1"
minor-version="0"
title="Default Title"
xmlns:epi="http://www.epicentric.com/deployment">

<epi:required-component component-id="template0005"
component-type="Style Types"
major-version="7"
minor-version="1"
/>

<epi:detail>
<style-info apply-template-header="true"
description="A description."
friendly-id="sss_grid.default"
id="sss0005style0001"
is-system="false"
primary-filename="sss-grid-default.jsp"
processing-type="JSP_BASED"
template-default="false"
template-uid="template0005"
title="SPS Default Grid"
visible="true"
/>
</epi:detail>
</epi:component>


I've been testing the XPath queries using transforms via xalan. Here is
the xsl :


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:epi="http://www.epicentric.com/deployment">

<xsl:template match="/">
<xsl:value-of select="//style-info[@description]"/>
<xsl:value-of select="//epi:component[@build-version]"/>
</xsl:template>

</xsl:stylesheet>


Questions :

1. <xsl:value-of select="//style-info[@description]"/> doesn't return
anything.
What expression returns "A description" ?

Is there a fully qualified expression returning the same value? Like

"//epi:component/epi:detail/style-info[@description]".

2. <xsl:value-of select="//epi:component[@build-version]"/>
What expression returns "Gold" ?
 
R

Romin

1: //epi:component/epi:detail/style-info[@description]/@description --
returns "A description".

2: /epi:component[@build-version]/@build-version - returns "Gold".

In both the expressions that you have used -- you are searching for the
XML element that has the specified attribute - which is ok. All you
need to do is add the remaining part of the expression i.e. the
attribute value that you want to extract out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top