0

I was given a XSLT-file which looks like this (only the relevant part):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:xls="http://www.w3.org/1999/XSL/Transform"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:step="http://www.stibosystems.com/step"
            xmlns="http://www.stibosystems.com/step"
            exclude-result-prefixes="xs xls">

<xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    <xsl:copy-of select="$newShopDoc/STEP-ProductInformation/AttributeList/Attribute[starts-with(xs:string(@ID), 'PA_')]" />
</xsl:copy>

I also tried this approach, as suggested:

<xsl:copy-of select="$newShopDoc/STEP-ProductInformation/AttributeList/Attribute[starts-with(xs:string(@ID), 'PA_')][not(@ID='PA_VENDOR')]" />

Now there was a change-request, to copy all elements, except one in particular. All elements are prefixed with a PA_ and so is the element, which shouldn't be copied. There are like 100 elements, so I really don't want to write every single element I need and leave out the one I don't need.

I read a bit into it and thus far, I can only see a solution in building a sub-structure with an if condition.

From what I saw though, there might be a solution with parentheses and the and keyword, but I havn't found the solution.

I'm not familiar with XSLT and there is probably an easy way to achieve my goal.

The element I want to exclude is called PA_VENDOR. Is it also possible to exclude more than 1 element, even though it isn't yet requested?

DasSaffe
  • 2,080
  • 1
  • 28
  • 67
  • The answer depends on which version of XSLT your processor supports. In XSLT 2.0 you can use the `except` operator. – michael.hor257k May 13 '20 at 13:46
  • unfortunatly, it is 1.0. I updated the question. I hope that `version` in the `stylesheet`-attribute corresponds to the XSLT-version. – DasSaffe May 13 '20 at 13:47
  • Not necessarily. The XSLT author is supposed to match the stylesheet's version to the processor's capability. To test the processor, see: https://stackoverflow.com/a/25245033/3016153 – michael.hor257k May 13 '20 at 14:07

1 Answers1

1

Without a reproducible example, all we can do is guess.

Looking at the code you already have, I would guess that your description:

All elements are prefixed with a PA_ and so is the element, which shouldn't be copied.

is incorrect. The instruction:

<xsl:copy-of select="$newShopDoc/STEP-ProductInformation/AttributeList/Attribute[starts-with(xs:string(@ID), 'PA_')]" />

copies all elements named Attribute that have an attribute named ID that starts with PA_.

Guessing further that the element you don't want to be included in this is also named Attribute and its ID attribute contains PA_VENDOR, you would need to change the instruction to something like:

<xsl:copy-of select="$newShopDoc/STEP-ProductInformation/AttributeList/Attribute[starts-with(@ID, 'PA_')][not(@ID='PA_VENDOR')]" />

Untested, because we have nothing to test against.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51