XSL question

Post Reply
starea1
Posts: 20
Joined: 21 May 2019, 13:32

Hi, as a first, please dont laugh - xml and xsl has never been my expertise, and now i am paying good price for that... :cry:

i am trying to extract list of the Busines Capabilities, description and parent BC name into CSV, but no luck...
I am getting capability names , description, but parent is presented by id (KB_666098_Class368), and cannot find the way to convert id to parent name...

Here is the code:

Code: Select all

	<xsl:output method="text"></xsl:output>
	
	
	
	
	<!-- Grab all the business capabilities -->
	<xsl:template match="knowledge_base">
		<xsl:text>Capability, Description, Parent</xsl:text>
		<xsl:text>&#xa;</xsl:text>
		<xsl:apply-templates select="/node()/simple_instance[type = 'Business_Capability']" mode="BusinessCapability">
			<xsl:sort case-order="lower-first" order="ascending" select="own_slot_value[slot_reference = 'name']/value"></xsl:sort>
		</xsl:apply-templates>
	</xsl:template>

	<!-- Render an Application_Provider instance -->
	<xsl:template match="node()" mode="BusinessCapability">
		<xsl:value-of select="own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		<xsl:text>, </xsl:text>
		<xsl:value-of select="replace(own_slot_value[slot_reference = 'description']/value, '&#xa;', '')"></xsl:value-of>
		<xsl:text>, </xsl:text>
		 <xsl:value-of select="own_slot_value[slot_reference = 'supports_business_capabilities']/value"></xsl:value-of>
		<xsl:text>&#xa;</xsl:text>
	</xsl:template>
</xsl:stylesheet>

Any help on that?


Thanks in advance!
Alex
JohnM
Posts: 478
Joined: 17 Feb 2009, 20:19

This should work - I haven't tested it. Explanation at the bottom.

Code: Select all

<xsl:output method="text"></xsl:output>
	<xsl:variable name="businessCaps" select="/node()/simple_instance[type = 'Business_Capability']"/>

	<!-- Grab all the business capabilities -->
	<xsl:template match="knowledge_base">
		<xsl:text>Capability, Description, Parent</xsl:text>
		<xsl:text>&#xa;</xsl:text>
		<xsl:apply-templates select="$businessCaps" mode="BusinessCapability">
			<xsl:sort case-order="lower-first" order="ascending" select="own_slot_value[slot_reference = 'name']/value"></xsl:sort>
		</xsl:apply-templates>
	</xsl:template>

	<!-- Render an Bus Cap instance -->
	<xsl:template match="node()" mode="BusinessCapability">
    <xsl:variable name="thisBusinessCap" select="$businessCaps[name=current()/own_slot_value[slot_reference = 'supports_business_capabilities']/value]"/>

		<xsl:value-of select="own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		<xsl:text>, </xsl:text>
		<xsl:value-of select="replace(own_slot_value[slot_reference = 'description']/value, '&#xa;', '')"></xsl:value-of>
		<xsl:text>, </xsl:text>
		 <xsl:value-of select="$thisBusinessCap/own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		<xsl:text>&#xa;</xsl:text>
	</xsl:template>
</xsl:stylesheet>
The variable holds all the Business Capability nodes - we can then reuse it (and it's faster).

In your template you were correctly getting the parent capability ID, but it is just the ID. You need to get the business capabilities nodes and pull out the one that matches that ID. The variable at the start of the template says find the business capability that matches the value of the id and lower down we say show the name slot of that object.

One caveat, if there are multiple parents then you'll get a list of nodes against current()/own_slot_value[slot_reference = 'supports_business_capabilities']/value and you'll need to add a for-each or apply-templates to get each of those. If you need help let us know.

Hope that makes sense. If not let me know and I'll do a more detailed breakdown for you
starea1
Posts: 20
Joined: 21 May 2019, 13:32

Hi John, thank you - that works!

following question - now i am trying to include 'realised_by_business_process' variable too, but getting same result as before. Do i need to create apply-template for the business processes too?
Here is code i am testing:

Code: Select all

<xsl:output method="text"></xsl:output>
	<xsl:variable name="businessCaps" select="/node()/simple_instance[type = 'Business_Capability']"/>
	
	<!-- Grab all the business capabilities -->
	<xsl:template match="knowledge_base">
		<xsl:text>Capability: Description: Parent: Process</xsl:text>
		<xsl:text>&#xa;</xsl:text>
		<xsl:apply-templates select="$businessCaps" mode="BusinessCapability">
			<xsl:sort case-order="lower-first" order="ascending" select="own_slot_value[slot_reference = 'name']/value"></xsl:sort>
		</xsl:apply-templates>
	</xsl:template>

	<!-- Render an Bus Cap instance -->
	<xsl:template match="node()" mode="BusinessCapability">
    <xsl:variable name="thisBusinessCap" select="$businessCaps[name=current()/own_slot_value[slot_reference = 'supports_business_capabilities']/value]"/>
	<xsl:variable name="thisBusinessproc" select="$businessCaps[name=current()/own_slot_value[slot_reference = 'realised_by_business_processes']/value]"/>
	
		<xsl:value-of select="own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		<xsl:text>: </xsl:text>
		<xsl:value-of select="replace(own_slot_value[slot_reference = 'description']/value, '&#xa;', '')"></xsl:value-of>
		<xsl:text>: </xsl:text>
		 <xsl:value-of select="$thisBusinessCap/own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		 <xsl:text>: </xsl:text>
		
		<!--Trying the new way to get instance_name  - does not work! -->
		<xsl:value-of select="$thisBusinessproc/own_slot_value[slot_reference = 'name']/value"></xsl:value-of>
		
		<xsl:text>: </xsl:text>
		<!--Trying the old way to get instance_id  - that works! -->
		<xsl:value-of select="replace(own_slot_value[slot_reference = 'realised_by_business_processes']/value, '&#xa;', '')"></xsl:value-of>
		
				
		<xsl:text>&#xa;</xsl:text>
	</xsl:template>

Thanks in advance
Alex
JohnM
Posts: 478
Joined: 17 Feb 2009, 20:19

This line needs correcting:
<xsl:variable name="thisBusinessproc" select="$businessCaps[name=current()/own_slot_value[slot_reference = 'realised_by_business_processes']/value]"/>

Create a variable at the top (after the business capability one) to hold all the Business Processes
<xsl:variable name="businessProcesses" select="/node()/simple_instance[type = 'Business_Process']"/>

in your template the line you have should read:
<xsl:variable name="thisBusinessproc" select="$businessProcesses[name=current()/own_slot_value[slot_reference = 'realised_by_business_processes']/value]"/>

What you are saying here is get all the business processes that match the id (or id's) in the 'realised_by_business_processes' slot of the business capability

Hope that helps
starea1
Posts: 20
Joined: 21 May 2019, 13:32

Hi John, thank you - that works great!
I think, i can see the pattern how that works..


Best regards
Alex
Post Reply