Using Parameters to match elements inx XSLT

  • Thread starter Thread starter 3
  • Start date Start date

3

New Member
I got the following template from another post..\[code\]<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext"><xsl:output omit-xml-declaration="yes" indent="yes"/><xsl:strip-space elements="*"/><xsl:param name="pUncertainElName" select="'second'"/><xsl:param name="pParentPath" select="'outerElement/innerElement'" /><xsl:param name="pOrderedNames" select="'|first|second|third|'"/><xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy></xsl:template><xsl:template match="outerElement/innerElement"> <xsl:variable name="vrtfFirstPass"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> <xsl:apply-templates select= "self::*[not(*[name() = $pUncertainElName]) or *[name()=$pUncertainElName and @missing-cause]]" mode="missing"/> </xsl:copy> </xsl:variable> <xsl:apply-templates select="ext:node-set($vrtfFirstPass)/*" mode="pass2"/></xsl:template><xsl:template match="*[@missing-cause]"/><xsl:template match="*" mode="missing"> <xsl:element name="{$pUncertainElName}"> <CharacterString>INSERTED BY TEMPLATE</CharacterString> </xsl:element></xsl:template><xsl:template match="outerElement/innerElement" mode="pass2"> <xsl:copy> <xsl:apply-templates> <xsl:sort data-type="number" select= "string-length(substring-before($pOrderedNames, concat('|', name(), '|') ) )"/> </xsl:apply-templates> </xsl:copy></xsl:template></xsl:stylesheet>\[/code\]The purpose is to add missing Elements add specific places that are missing in the source document. The sourcedocument looks like this\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><doc> <outerElement> <innerElement> <first> <textElement>Some Text</textElement> </first> <second missing-cause="bla" /> <third> <textElement>Some Text</textElement> </third> </innerElement> </outerElement></doc>\[/code\]I have to add a lot of elements like this in a similar way so I want to use parameters to specify the parents path and the element I want to insert.So here comes the first question: How do I use a parameter in a match? match="$parameter" or variants do not seem to work.And the second one:There is still a problem with adding the element with this template which i think comes from the second pass. If my document does look like posted above it flattens the output to \[code\]<doc> <outerElement>Some TextSome TextINSERTED BY TEMPLATE</outerElement></doc>\[/code\]if the is missing its working as it should. There is missing something most likely in the buildup of the second path but i can't figure out how to fix this.And the last.. Is it ok to call this template with different parameters like 20 times on a single document to transform it or should i try something else?Thanks for help again and sorry I am new to this ;)
 
Back
Top