By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,078 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,078 IT Pros & Developers. It's quick & easy.

XPath query difficulty...

P: n/a
I'm trying to construct an XPath and it is giving me trouble. I have
an XML that contains a "Routine". The routine contains "Steps". The
steps have different types. Some types of steps have more steps
contained within them (substeps). I want to get a list of all of the
steps in a routine, including any substeps...but excluding substeps
that occur in a particular type of step ("Subroutine").

Below is a simplified example XML. The query I envision would return
all of the steps in the routine, including substeps found in the
"Loop" step type and "Condition" step type...but NOT including any
steps that are anywhere within a "Subroutine" step.

Any thoughts? My sincerest thanks in advance!

-----

<Routine>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</Steps>
</Step>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Condition</Type>
<TrueSteps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</TrueSteps>
<FalseSteps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</FalseSteps>
</Step>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Subroutine</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</Steps>
</Step>
</Steps>
</Routine>
Sep 26 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'm trying to construct an XPath and it is giving me trouble. I have
an XML that contains a "Routine". The routine contains "Steps". The
steps have different types. Some types of steps have more steps
contained within them (substeps). I want to get a list of all of the
steps in a routine, including any substeps...but excluding substeps
that occur in a particular type of step ("Subroutine").


//Step[not(ancestor::Type[. = ' Subroutine '])]

Cheers,

Dimitre Novatchev

"oopsatwork" <mk********@gmail.comwrote in message
news:e5**********************************@d77g2000 hsb.googlegroups.com...
I'm trying to construct an XPath and it is giving me trouble. I have
an XML that contains a "Routine". The routine contains "Steps". The
steps have different types. Some types of steps have more steps
contained within them (substeps). I want to get a list of all of the
steps in a routine, including any substeps...but excluding substeps
that occur in a particular type of step ("Subroutine").

Below is a simplified example XML. The query I envision would return
all of the steps in the routine, including substeps found in the
"Loop" step type and "Condition" step type...but NOT including any
steps that are anywhere within a "Subroutine" step.

Any thoughts? My sincerest thanks in advance!

-----

<Routine>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</Steps>
</Step>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Condition</Type>
<TrueSteps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</TrueSteps>
<FalseSteps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</FalseSteps>
</Step>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Subroutine</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
<Step>
<Type>Loop</Type>
<Steps>
<Step>
<Type>Calculation</Type>
<Other>stuff</Other>
</Step>
</Steps>
</Step>
</Steps>
</Step>
</Steps>
</Routine>

Sep 27 '08 #2

P: n/a
On Sep 27, 12:55*am, oopsatwork <mkimber...@gmail.comwrote:
I'm trying to construct an XPath and it is giving me trouble. *I have
an XML that contains a "Routine". *The routine contains "Steps". *The
steps have different types. *Some types of steps have more steps
contained within them (substeps). *I want to get a list of all of the
steps in a routine, including any substeps...but excluding substeps
that occur in a particular type of step ("Subroutine").
I would think, this should work (not tested, though)

//Step[not(ancestor::Step[Type = 'Subroutine'])]

Regards,
Mukul
Sep 27 '08 #3

P: n/a
//Step[not(ancestor::Step[Type = 'Subroutine'])]
You guys are pimps...thanks for the help!

Sep 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.