Accessing the current Element in p:for-each and p:viewport

Hi,

I'm trying to do something that should be fairly basic, but I cannot make it work: I want to access attribute and child element values of the matched node in p:for-each or p:viewport, but the example below does not work.

(Background: I have a list of new publications in my subject area and I want to produce sublists according to some classification. To produce these sublists I need to specify their names somehow.)

Best,
Denis

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:c="http://www.w3.org/ns/xproc-step"
                version="3.0"
                name="main">

  <!-- group definitions -->

    <p:input port="source">
      <p:inline>
        <groups>
          <group name="Group One as Attribute">
            <name>Group One as Element</name>
            <classification>A</classification>
            <classification>B</classification>
          </group>
          <group name="Group Two as Attribute">
            <name>Group Two as Element</name>
            <classification>C</classification>
          </group>
        </groups>
      </p:inline>
    </p:input>

  <p:for-each>
    <p:with-input select="//group"/>

    <p:variable name="groupName" select="./@name"/>

   <p:identity message="Name as Attribute: {./@name}"/>
   <p:identity message="Name as Element: {./name}"/>
   <p:identity message="Group: {.}"></p:identity>
  </p:for-each>

  <p:viewport match="group">
    <p:variable name="groupName" select="./@name"/>

    <p:identity message="Name as Attribute: {./@name}"/>
    <p:identity message="Name as Element: {./name}"/>
    <p:identity message="Group: {.}"></p:identity>
  </p:viewport>

</p:declare-step>

Received on Thursday, 17 April 2025 08:39:58 UTC