Advanced muenchian grouping: group by items in child collection - xslt-1.0

I'm familiar with simple muenchian grouping in XSL, but I've encountered a problem, which I honestly don't even know, how to approach it.
So I've got an XML:
<whiskies>
<whisky name="ABC" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="70" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="DEF" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="GHI" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="30" date=""/>
</bottles>
<comments/>
</whisky>
<whiskies>
And the goal is to group the whiskies by levels of a bottle:
So level="0" is considered empty.
Anything from level="1" to level="99" is considered open.
And level="100" is considered unopened.
So the transformed result (will be done in HTML) should look like this:
<h1>Empty</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
<h1>Open</h1>
<ul>
<li>ABC</li>
<li>GHI</li>
</ul>
<h1>Unopened</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
As you can see, the same whisky can show up in multiple groups, depending on how much bottles there are and how full those bottles are.
The second problem is, that the "Open" group doesn't have an exact value and can be aynthing from 1 to 99.
So yeah, don't really know if this can be solved at all or how to even start on this. Any tips appreciated.

I don't think you want to use Muenchian grouping for this. You would need to define a key that enumerates all values in the range from 1 to 99 - and I believe that would take away any advantage that using a key would otherwise bring.
Since your result has either exactly or at most 3 groups (your question is ambiguous in this respect), you could do simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="whisky[bottles/bottle/#level=0]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="whisky[bottles/bottle[#level>0 and #level < 100]]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="whisky[bottles/bottle/#level=100]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
to get (after fixing the input to be a well-formed XML!):
Result
<?xml version="1.0" encoding="utf-8"?>
<output>
<group status="empty">
<name>ABC</name>
<name>DEF</name>
</group>
<group status="open">
<name>ABC</name>
<name>GHI</name>
</group>
<group status="unopened">
<name>ABC</name>
<name>DEF</name>
</group>
</output>
Make your own adjustment for HTML output.
Added:
Here is an alternative approach using keys (though still not Muenchian grouping) which might be more performant:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="w" match="whisky" use="bottles/bottle/#level" />
<xsl:key name="w1" match="whisky" use="boolean(bottles/bottle[#level!=0 and #level!=100])" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('w', 0)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('w1', true())">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('w', 100)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
Or even:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="bottle" match="bottle" use="ceiling(#level div 99)" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('bottle', 0)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('bottle', 1)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('bottle', 2)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>

If you did want to use xsl:key, you could create 3 of them with the filter criteria:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:key name="Empty" match="whisky[bottles/bottle/#level=0]" use="#name"/>
<xsl:key name="Open" match="whisky[bottles/bottle/#level[. > 1 and . < 99]]" use="#name"/>
<xsl:key name="Unopened" match="whisky[bottles/bottle/#level=100]" use="#name"/>
<xsl:template match="/">
<xsl:variable name="whiskies" select="/whiskies/whisky/#name"/>
<xsl:for-each select="document('')/xsl:stylesheet/xsl:key/#name">
<xsl:variable name="status" select="."/>
<h1><xsl:value-of select="$status"/></h1>
<ul>
<xsl:for-each select="$whiskies[key($status, .)]">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Related

XSLT: Need to convert name value pair content into XML

I'm new to XSLT. I have a requirement to convert an XML containing name value pair into target XML.
I need to generate a target XML where each FieldName is an element name and it value is FieldValue. Please find below the output which I need.
Thanks in advance for the help.
Source XML:
<SC>
<Header>
<Record>
<FieldName>Schema</FieldName>
<FieldValue>OrderHeader</FieldValue>
</Record>
<Record>
<FieldName>Order</FieldName>
<FieldValue>1234</FieldValue>
</Record>
</Header>
<Detail>
<Record>
<FieldName>Schema</FieldName>
<FieldValue>OrderItem</FieldValue>
</Record>
<Record>
<FieldName>Item</FieldName>
<FieldValue>1</FieldValue>
</Record>
<Record>
<FieldName>Qty</FieldName>
<FieldValue>10</FieldValue>
</Record>
</Detail>
<Detail>
<Record>
<FieldName>Schema</FieldName>
<FieldValue>OrderItem</FieldValue>
</Record>
<Record>
<FieldName>Item</FieldName>
<FieldValue>2</FieldValue>
</Record>
<Record>
<FieldName>Qty</FieldName>
<FieldValue>20</FieldValue>
</Record>
</Detail>
</SC>
Target XML to be generated:
<SC>
<OrderHeader>
<Order>1234</Order>
</OrderHeader>
<OrderItem>
<Item>1</Item>
<Qty>10</Qty>
</OrderItem>
<OrderItem>
<Item>2</Item>
<Qty>20</Qty>
</OrderItem>
</SC>
XSLT which I tried: I'm not getting the desired output
<xsl:template match="Header">
<xsl:apply-templates select="Record"/>
</xsl:template>
<xsl:template match="Record">
<xsl:if test="FieldName = 'Structure'">
<xsl:element name="{FieldValue}">
<xsl:value-of select="./text()"/>
</xsl:element>
</xsl:if>
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
Here's another option that is similar to Martin's.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Header|Detail">
<xsl:element name="{Record[1]/FieldValue}">
<xsl:apply-templates select="Record[position()>1]"/>
</xsl:element>
</xsl:template>
<xsl:template match="Record">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
It seems you want to process the first Record child as a container element and the following siblings are to be transformed as in your description:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="SC">
<xsl:copy>
<xsl:apply-templates select="*/Record[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SC/*/Record[1]">
<xsl:element name="{FieldValue}">
<xsl:apply-templates select="following-sibling::Record"/>
</xsl:element>
</xsl:template>
<xsl:template match="SC/*/Record[position() gt 1]">
<xsl:element name="{FieldName}">
<xsl:value-of select="FieldValue"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Based on the object corresponding values should be taken using xslt

INPUT XML
<root>
<file1>
<commodity>
<units>1</units>
<obj>mango</obj>
</commodity>
<commodity>
<units>5</units>
<obj>guava</obj>
</commodity>
</file1>
<file2>
<category>
<object>guava</object>
<type>CAT1</type>
<colour>green</colour>
</category>
<category>
<object>mango</object>
<type>CAT2</type>
<colour>yellow</colour>
</category>
</file2>
</root>
I need to compare the values of obj in file1 and object in file2 under root, if same I need to take their corresponding units, type and colour and produce the following output using xslt.
OUTPUT XML
<output>
<com>
<name>guava</name>
<num>5</num>
<category>CAT1</category>
<col>green</col>
</com>
<com>
<name>mango</name>
<num>1</num>
<category>CAT2</category>
<col>yellow</col>
</com>
</output>
I tried the below XSLT but the response is not as expected. Its not looping properly. Could you please tell me where I am going wrong.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:key name="object-search" match="root/file1/commodity" use="obj" />
<xsl:template match="/">
<output>
<xsl:for-each select="key('object-search', //category/object)">
<com>
<name>
<xsl:value-of select="obj" />
</name>
<num>
<xsl:value-of select="units" />
</num>
<category>
<xsl:value-of
select="//root/file2/category/type" />
</category>
<col>
<xsl:value-of
select="//root/file2/category/colour" />
</col>
</com>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
Try it this way:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="cat" match="category" use="object" />
<xsl:template match="/root">
<output>
<xsl:for-each select="file1/commodity">
<com>
<name>
<xsl:value-of select="obj" />
</name>
<num>
<xsl:value-of select="units" />
</num>
<xsl:variable name="cat" select="key('cat', obj)" />
<category>
<xsl:value-of select="$cat/type" />
</category>
<col>
<xsl:value-of select="$cat/colour" />
</col>
</com>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
Note that the result is slightly different from what you posted:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<com>
<name>mango</name>
<num>1</num>
<category>CAT2</category>
<col>yellow</col>
</com>
<com>
<name>guava</name>
<num>5</num>
<category>CAT1</category>
<col>green</col>
</com>
</output>
Alternatively, you could do:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="com" match="commodity" use="obj" />
<xsl:template match="/root">
<output>
<xsl:for-each select="file2/category">
<xsl:variable name="com" select="key('com', object)" />
<com>
<name>
<xsl:value-of select="$com/obj" />
</name>
<num>
<xsl:value-of select="$com/units" />
</num>
<category>
<xsl:value-of select="type" />
</category>
<col>
<xsl:value-of select="colour" />
</col>
</com>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
and get:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<com>
<name>guava</name>
<num>5</num>
<category>CAT1</category>
<col>green</col>
</com>
<com>
<name>mango</name>
<num>1</num>
<category>CAT2</category>
<col>yellow</col>
</com>
</output>

xslt nested transformation : unable to transnform

I am learning XSLT and trying to transform below xml. But couldn't achieve the task
<sample id="7">
<land1 id="8">
<owner>TOMMY</owner>
<type>INDIVIDUAL</type>
<hint>TOM_INDIVIDUAL</hint>
<date>12.02.2014</date>
<text>land details</text>
<number>1</number>
<cost>WIDERRUFLICH</cost>
</land1>
</sample>
and trying to convert above into
<table name="sample">
<tablename="land1">
<rel name="owner" value="TOMMY"/>
<rel name="type" value="INDIVIDUAL"/>
<rel name="<hint" value="TOM_INDIVIDUAL"/>
<rel name="date" value="12.02.2014"/>
<rel name="details" value="land details"/>
<rel name="number" value="1"/>
<rel name="cost" value="25%"/>
</table>
</table>
I tried below to generate the same, but it's not working.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="*">
<xsl:if test="current().count(*)>0">
<xsl:element name="table">
<xsl:attribute name="name">
<xsl:value-of select="name(.)"/>
</xsl:attribute>
<xsl:apply-templates select="/"
</xsl:element>
</xsl:if>
<xsl:if test="current().count(*)=0">
<xsl:element name="rel">
<xsl:attribute name="name">
<xsl:value-of select="name(.)"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="current()"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Can someone please let me know where I am doing wrong?
Can someone please let me know where I am doing wrong?
Well, for one thing, current().count(*)>0 is not a valid expression.
And you have <xsl:apply-templates select="/" without closing the tag. Which may be a good thing - because if it worked, it would have created an infinite loop.
I also don't understand the overall logic of your approach. Couldn't you do simply:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[*]">
<table name="{name()}">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="*">
<rel name="{name()}" value="{.}"/>
</xsl:template>
</xsl:stylesheet>
Added:
every element with an attribute should also be a table. For example,
in the above xml, <land1 id="8"> has children and your logic works
fine. But my inout can also contain <land1 id="8"/>. Now even though
it doesn't have any child elements, still element name has to be
considered as Table
Then use:
<xsl:template match="*[#*]">
instead of:
<xsl:template match="*[*]">

template not getting applied with XSLT

I am using xslt to convert xml to xml.
<root>
<elem>
<confs>
<conf1>1</conf1>
<conf2>2</conf2>
</confs>
</elem>
</root>
My XSL
<xsl:template match="elem">
<xsl:copy>
<xsl:attribute name="className">confs</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="confs">
<confs>
<xsl:for-each select="*">
<conf>
<value>
<xsl:value-of select="node()"></xsl:value-of>
</value>
</conf>
</confs>
</xsl:template>
desired output:
<root>
<elem className="confs>
<confs>
<conf>
<value>1</value>
</conf>
<conf>
<value>1</value>
</conf>
</confs>
</elem>
</root>
When ran each template individaully they are good. But I run both the confs template is not affected at all.
Any help?
I believe the most straightforward way to achieve your output would be by:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="elem">
<elem className="confs">
<xsl:apply-templates/>
</elem>
</xsl:template>
<xsl:template match="confs/*">
<conf>
<value>
<xsl:value-of select="."/>
</value>
</conf>
</xsl:template>
</xsl:stylesheet>

XSL 1.0 - Hiding Child nodes when child element is Null

I have been trying to make child elements of my structure hide based upon them being empty.
From reading other posts I found this Remove parent node if a child node is empty but I don't understand it enough to implement it in my XSL. I have had a try at applying the linked post to my XSL but it does not make the desired changes to my output.
So my XML is like this:
<?xml version="1.0" encoding="UTF-8" ?>
<exchange>
<sce>
<sce.srs>
<sce_scjc.sce.srs>140008305/1</sce_scjc.sce.srs>
<sce_seq2.sce.srs>01</sce_seq2.sce.srs>
<sce_stuc.sce.srs>140008305</sce_stuc.sce.srs>
<spr>
<spr.cams>
<spr_code.spr.cams>140008305/1</spr_code.spr.cams>
<prs_code.spr.cams>77711925</prs_code.spr.cams>
<prs>
<prs.mensys>
<prs_code.prs.mensys>77711925</prs_code.prs.mensys>
<prs_name.prs.mensys>Johan</prs_name.prs.mensys>
</prs.mensys>
</prs>
</spr.cams>
</spr>
</sce.srs>
<sce.srs>
<sce_scjc.sce.srs>151516736/1</sce_scjc.sce.srs>
<sce_seq2.sce.srs>01</sce_seq2.sce.srs>
<sce_stuc.sce.srs>151516736</sce_stuc.sce.srs>
<spr>
<spr.cams>
<spr_code.spr.cams>151516736/1</spr_code.spr.cams>
<prs_code.spr.cams>77709062</prs_code.spr.cams>
<prs>
<prs.mensys>
<prs_code.prs.mensys>77709062</prs_code.prs.mensys>
<prs_name.prs.mensys>Evangelia</prs_name.prs.mensys>
</prs.mensys>
</prs>
</spr.cams>
</spr>
</sce.srs>
<sce.srs>
<sce_scjc.sce.srs>150052468/1</sce_scjc.sce.srs>
<sce_seq2.sce.srs>01</sce_seq2.sce.srs>
<sce_stuc.sce.srs>150052468</sce_stuc.sce.srs>
<spr>
<spr.cams>
<spr_code.spr.cams>150052468/1</spr_code.spr.cams>
<prs_code.spr.cams/>
</spr.cams>
</spr>
</sce.srs>
</sce>
</exchange>
And my XSL looks like the passaage below. I have a nil element template that I added in as I thought looking for a value was easier than looking for a nulll so happy for it to come out if not needed.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/exchange/sce">
<ImportTask>
<EntityRelationshipEntities>
<xsl:apply-templates select="node()|#*"/>
</EntityRelationshipEntities>
</ImportTask>
</xsl:template>
<xsl:template name="nilElement">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="string($value)">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xsi:nil" namespace="http://www.w3.org/2001/XMLSchema-instance">True</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="sce.srs[not(*/AttributeValue[not(#AttributeValue='True')])]">
<xsl:for-each select="spr/spr.cams">
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode><xsl:value-of select="../../sce_stuc.sce.srs"/></EntityCode>
<AttributeValue>
<xsl:call-template name="nilElement">
<xsl:with-param name="value" select="prs/prs.mensys/prs_name.prs.mensys"/>
</xsl:call-template>
</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
</xsl:for-each>
</xsl:template>
<xsl:template match="AttributeValue[#AttributeValue = 'True']"/>
</xsl:stylesheet>
So this currently gives me:
<ImportTask xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EntityRelationshipEntities>
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode>151514490</EntityCode>
<AttributeValue xsi:nil="True"/>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode>140008305</EntityCode>
<AttributeValue>Johan</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
<EntityRelationshipEntity>
<EntityCode>151516736</EntityCode>
<AttributeValue>Evangelia</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
</EntityRelationshipEntities>
</ImportTask>
What I would like to produce is out those where is not null. This would mean that the child below is not output:
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode>151514490</EntityCode>
<AttributeValue xsi:nil="True"/>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
But the others would be output something like this:
<ImportTask xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EntityRelationshipEntities>
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode>140008305</EntityCode>
<AttributeValue>Johan</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
<EntityRelationshipEntity>
<EntityCode>151516736</EntityCode>
<AttributeValue>Evangelia</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
</EntityRelationshipEntities>
</ImportTask>
Can someone help me apply this correctly?
Many thanks
Jonah
Perhaps I am missing something, but couldn't this be simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/exchange/sce">
<ImportTask xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EntityRelationshipEntities>
<xsl:apply-templates select="sce.srs/spr/spr.cams[string(prs/prs.mensys/prs_name.prs.mensys)]"/>
</EntityRelationshipEntities>
</ImportTask>
</xsl:template>
<xsl:template match="spr.cams">
<EntityRelationshipEntity>
<ErRef>ERREF_21</ErRef>
<EntityCode>
<xsl:value-of select="../../sce_stuc.sce.srs"/>
</EntityCode>
<AttributeValue>
<xsl:value-of select="prs/prs.mensys/prs_name.prs.mensys"/>
</AttributeValue>
<Action>VALUEONLY</Action>
</EntityRelationshipEntity>
</xsl:template>
</xsl:stylesheet>