Auxiliary XSLT for building specs/MRGs for XML

Here is a simple XSLT which helps me to “extract” the structure from XML file. I use it for building specifications/designs/MRGs in MS Excel format:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:variable name="default_indent" select="'& #x9;'" />
	<xsl:template match="/">
		<xsl:for-each select=".">
			<xsl:call-template name="processElement" />
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="processElement">
		<xsl:param name="indent" select="''" />

		<xsl:value-of select="$indent"/>
		<xsl:value-of select="name()"/>
		<xsl:text>& #xA;</xsl:text>
		
		<xsl:for-each select="@*">
			<xsl:value-of select="concat($indent, $default_indent)"/>
			<xsl:value-of select="'@'"/>
			<xsl:value-of select="name()"/>
			<xsl:text>& #xA;</xsl:text>
		</xsl:for-each>

		<xsl:if test="count(./*) != 0">
			<xsl:for-each select="./*">
				<xsl:call-template name="processElement">
					<xsl:with-param name="indent">
						<xsl:value-of select="concat($indent, $default_indent)"/>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

Continue reading

Advertisements

GXS AI: models analyzer

As I wrote before, I’m often trying to use/create some tools/scripts which helps me to do different things – build the test data, compare outputs or check the models. For example when I was working a lot with GXS AI I created a tool which showed me the list of the variables and arrays used in the maps + some “assumptions” (for example, if a variable is not used). Also, it generated a code to check all the arrays (they all should be empty at the end of the translation). It helped us to keep the maps clean. There is no Print to File option in GXS AI Workbench (like Sterling’s MapEditor has) so often it was hard to see the whole picture, especially when the map contained hundreds or thousands lines.

Such tool would also help you to migrate maps from GXS AI to Sterling GIS/SI (or another EAI) and back.

Here are some screenshots just to give you an idea:


Continue reading

XSLT: tips and tricks: how to process node1, node2, …, nodeN

Very often people don’t understand how to process structures like

<forecast>
      <qty1>1</qty1>
      <date1>01022014</date1>

      <qty2>1</qty2>
      <date2>01022014</date2><qtyN>1</qtyN>
      <dateN>01022014</dateN>
</forecast>

They create N templates or repeat the same code again and again, changing the names: qty1/date1, qty2/date2, … But all they need to do is to use the name() function, like this:

<xsl:for-each select="forecast/*[ starts-with(name(), 'qty') ]">

I think the idea is self explanatory…

Gennady Kim