deleyd
asked on
XSLT Detect processing-instruction in current-group returned by for-each-group
I want to test a group returned from a "for-each-group" to see if it consists of a single node which is a processing-instruction.
Currently in the choose statement, the first when and second when work. The second when tests for a blank node.
The third when attempts to test for a processing-instruction, but it does not work.
I need some syntax that will detect a processing instruction.
Currently in the choose statement, the first when and second when work. The second when tests for a blank node.
The third when attempts to test for a processing-instruction, but it does not work.
I need some syntax that will detect a processing instruction.
<xsl:for-each-group select="node()" group-adjacent="...">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:apply-templates select="current-group()" mode="..."/>
</xsl:when>
<xsl:when test="count(current-group()) eq 1 and current-group()/self::text() and not(normalize-space(current-group()))">
<!-- skip blank nodes -->
</xsl:when>
<xsl:when test="count(current-group()) eq 1 and current-group()/self::processing-instruction()">
do special stuff...
</xsl:when>
<xsl:otherwise>
do stuff...
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
The input might be:
<block>
<section>
...
</section>
<section>
...
</section>
<?foo bar1?>
<section>
...
</section>
<section>
...
</section>
<?foo bar2?>
<section>
...
</section>
</block>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK, "its on a list or not" I assume means that the element name is on a list?
so, basically that means that all elements on a list are grouped together
and everything in between (not on a list) are grouped together
if the processing instruction are not on that list (and I assume because otherwise they would be in the first when clause)
they would group together with the whitespace nodes before and after
basically my assumption is right
count(current-group()) eq 1 and current-group()/self::proc essing-ins truction()
will not be true() because the current-group is a sequence of more than one item
so, basically that means that all elements on a list are grouped together
and everything in between (not on a list) are grouped together
if the processing instruction are not on that list (and I assume because otherwise they would be in the first when clause)
they would group together with the whitespace nodes before and after
basically my assumption is right
count(current-group()) eq 1 and current-group()/self::proc
will not be true() because the current-group is a sequence of more than one item
ASKER
Oh and forgot to mention, if I throw in a <value-of select="current-group()"/> I do get the name from the processing instruction it's on.
ASKER
OK let me try that I'll get back (I'm not at the office right now).
note that in an adjacent I would do something like this
group-adjacent="if(x:boole an_functio n(.)) then(generate-id()) else('not-listed')"
it has the advantage that each elements that renders the boolean true is in its seperate group
and all the others are grouped too
you can then in the fallback group do an apply-templates to a different mode and take action based on the node type
it is a bit more convenient (less when clauses) and better readable code
just suggesting
group-adjacent="if(x:boole
it has the advantage that each elements that renders the boolean true is in its seperate group
and all the others are grouped too
you can then in the fallback group do an apply-templates to a different mode and take action based on the node type
it is a bit more convenient (less when clauses) and better readable code
just suggesting
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So I'm actually trying to match on a sequence containing a processing instruction mixed with whitespace nodes? Those darn whitespace nodes. Maybe there's a way I can filter them out beforehand.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh I see it's returning the content Plus the whitespace, which probably does not have any spaces in it.
ASKER
Thank you very much for the help!
welcome
ASKER
I've tried all sorts of combinations of processing-instruction() and haven't come up with anything that works. Not sure if I need the test for count = 1. The debugger shows it on the processing instruction, and jumping to the otherwise clause no matter what when statement I put in there. (Altova XMLSpy. Is there a way I can get that debugger to tell me something useful?)