1

I need an help regarding the XSL ,please find my xml below

<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:i="http://www.w3.org/2001/XMLSchemainstance">
  <TEST>
    <TEST1>
      <TEST2>
        <A>
          <Rule>e1fa7f63820a406bb97f1c1b11af8d09</Rule>
          <MountPoint>0</MountPoint>
        </A>
        <A>
          <Rule>917271928cea4a75bdfa903b49ed23e5</Rule>
          <MountPoint>0</MountPoint>
        </A>
        <A>
          <Rule>6b6336722d574e8285b73192ea057b45</Rule>
          <MountPoint>0</MountPoint>
        </A>
      </TEST2>
    </TEST1>
    <CHECK>
      <CHECK1>
        <Rule>
          <Name>test1</Name>
          <ID>6b6336722d574e8285b73192ea057b45</ID>
          <Type>DicomHeaderAttribute</Type>
          <Category>SeriesDate</Category>
          <Operator>Equals</Operator>
          <Value>as</Value>
        </Rule>
        <Rule>
          <Name>sdsd</Name>
          <ID>e1fa7f63820a406bb97f1c1b11af8d09</ID>
          <Type>DicomHeaderAttribute</Type>
          <Category>SeriesInformation</Category>
          <Operator>Equals</Operator>
          <Value>sdsdsd</Value>
        </Rule>
        <Rule>
          <Name>fdfdf</Name>
          <ID>917271928cea4a75bdfa903b49ed23e5</ID>
          <Type>DicomHeaderAttribute</Type>
          <Category>ReferringPhysician</Category>
          <Operator>Equals</Operator>
          <Value>assd</Value>
        </Rule>
      </CHECK1>
    </CHECK>
  </TEST>
</TEST>

In the above xml i need to remove the rules matching with Category value as 'SeriesInformation', and also the corresponding 'A' node which matches with the ID of the 'SeriesInformation' Rule,

The expected XML:

<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:i="http://www.w3.org/2001/XMLSchemainstance">
  <TEST>
    <TEST1>
      <TEST2>
        <A>
          <Rule>917271928cea4a75bdfa903b49ed23e5</Rule>
          <MountPoint>0</MountPoint>
        </A>
        <A>
          <Rule>6b6336722d574e8285b73192ea057b45</Rule>
          <MountPoint>0</MountPoint>
        </A>
      </TEST2>
    </TEST1>
    <CHECK>
      <CHECK1>
        <Rule>
          <Name>test1</Name>
          <ID>6b6336722d574e8285b73192ea057b45</ID>
          <Type>DicomHeaderAttribute</Type>
          <Category>SeriesDate</Category>
          <Operator>Equals</Operator>
          <Value>as</Value>
        </Rule>
        <Rule>
          <Name>fdfdf</Name>
          <ID>917271928cea4a75bdfa903b49ed23e5</ID>
          <Type>DicomHeaderAttribute</Type>
          <Category>ReferringPhysician</Category>
          <Operator>Equals</Operator>
          <Value>assd</Value>
        </Rule>
      </CHECK1>
    </CHECK>
  </TEST>
</TEST>

Please help in XSL.

Hi ,this is xsl iam using

 <?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="Rule[Category = 'SeriesInformation']">
  </xsl:template>
</xsl:stylesheet>

iam not able to forward after that,, iam able to delete the rule that matches with category as SeriesInformation, but after that how to delete the A nodes depending on ID iam not able to do

1 Answers1

2

To remove the A elements, you could define a key to look up the Rule elements by ID

<xsl:key name="rule" match="Rule[ID]" use="ID" />

Then, the template match to ignore the A elements is as follows:

<xsl:template match="A[key('rule', Rule)/Category='SeriesInformation']" />

Try this XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" />
    <xsl:key name="rule" match="Rule[ID]" use="ID" />

    <xsl:template match="Rule[Category='SeriesInformation']" />

    <xsl:template match="A[key('rule', Rule)/Category='SeriesInformation']" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Tim C
  • 70,053
  • 14
  • 74
  • 93