Skip to content

XSLT to add @xml:id to elements that don't have them? #32

Description

@bitparity

So this would be a sample XML file

<body>
   <text>
      <p xml:id="l-01">line 1</p>
      <p>line 2</p>
      <p>line 3</p>
      <p>line 4</p>
   </text>
</body>

So what I'd be interested in is an XSLT file that looks at all <p> elements, checks to see if an @xml:id exists, if one doesn't, to add and generate one.

So the transformed XML file would look like below, but with the understanding the @xml:id might be another generated ID (so as to keep things simple).

<body>
   <text>
      <p xml:id="l-01">line 1</p>
      <p xml:id="l-02">line 2</p>
      <p xml:id="l-03">line 3</p>
      <p xml:id="l-04">line 4</p>
   </text>
</body>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions