1

My input xml:

<?xml version = "1.0" encoding = "UTF-8"?>
&lt;InfoReturn>
    &lt;LicenseInfo>
        &lt;licenseType>1&lt;/licenseType>
        &lt;licenseTypeDescAr>دائمة&lt;/licenseTypeDescAr>
        &lt;licenseTypeDescEn>Permanent&lt;/licenseTypeDescEn>
        &lt;centerId>1&lt;/centerId>
        &lt;centerNameA>مرور ديرة&lt;/centerNameA>
        &lt;centerNameE>TRAFFIC DEIRA&lt;/centerNameE>
        &lt;interimExpiryDate>2018-09-30T00:00:00.000Z&lt;/interimExpiryDate>
        &lt;licenseStatusArabic>مع المالك&lt;/licenseStatusArabic>
        &lt;licenseStatusEnglish>With Owner&lt;/licenseStatusEnglish>
        &lt;hasEyeTest>0&lt;/hasEyeTest>
        &lt;personId>1004257701&lt;/personId>
        &lt;isSpecialExpiryDesA>لا&lt;/isSpecialExpiryDesA>
        &lt;isSpecialExpiryDesE>NO&lt;/isSpecialExpiryDesE>
    &lt;/LicenseInfo>           
&lt;/InfoReturn>

Allowed fields will be passed as centerId | centerNameE | personId

The output XML which I am looking for is:

<?xml version = "1.0" encoding = "UTF-8"?>
&lt;InfoReturn>     
    &lt;LicenseInfo>
        &lt;centerId>1&lt;/centerId>
        &lt;centerNameE>TRAFFIC DEIRA&lt;/centerNameE>
        &lt;personId>1004257701&lt;/personId>
    &lt;/LicenseInfo>           
&lt;/InfoReturn>

Please provide XSLT for this solution.

1

In XSLT 3.0 this would simply be:

<xsl:param name="allowed-elements" as="xs:string" required="yes"/>

<xsl:variable name="filter" as="xs:string*" 
              select="tokenize($allowed-elements, '\|') ! normalize-space()"/>

<xsl:mode on-no-match="shallow-copy"/>

<xsl:template match="LicenseInfo/*[not(name() = $filter)]"/>
  • The root element will always get change. Now it's licenseInfo and that could be some other value also. the input xml will always pass as a string. – Siva Katta Feb 28 at 13:06
  • If you want to supply more information about your requirements, please do that by editing your original question, not by commenting on answers. – Michael Kay Feb 28 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.