Subject: Re: [xsl] Q: XSLT 1.0 output of namespace From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Mon, 16 Aug 2010 17:24:56 +0200 |
Michael, thank you! Your <xsl:if test="count(. | ../@*) != count(../@*)"> works fine and is definitely much simpler than this <xsl:variable name="isAttribute"> <xsl:apply-templates select="."/> </xsl:variable> <xsl:if test="$isAttribute=''"> > Why are you processing attribute nodes and namespace nodes > using the same code? Could you avoid doing this? Template "doOutput" below gets called for nodes selected by a dynamic XPath expression and should generate "readable" output. While <xsl:copy-of select="."/> is fine for text, node, comment and PI nodes the default output for attribute nodes and namespace nodes is empty., "doOutput" just outputs attributes and namespaces as required. Mit besten Gruessen / Best wishes, Hermann Stamm-Wilbrandt Developer, XML Compiler, L3 WebSphere DataPower SOA Appliances ---------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 From: Michael Kay <mike@xxxxxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: 08/16/2010 03:00 PM Subject: Re: [xsl] Q: XSLT 1.0 output of namespace I think you are trying to test whether the current node is an attribute node or a namespace node. As you've discovered, that's surprisingly tricky in XPath 1.0. Your way is one possibility, another is test="count(. | ../@*) = count(../@*)" But it might be better to stand back and ask why you are in a position where you need to ask this question. Why are you processing attribute nodes and namespace nodes using the same code? Could you avoid doing this? Michael Kay Saxonica On 16/08/2010 13:35, Hermann Stamm-Wilbrandt wrote: > Hello, > > this is a pure XSLT 1.0 question. > > Below template does the (readable) output of the current node even for > attribute and namespace nodes. > In the spec the following is stated: > "There is no pattern that can match a namespace node, ...". > > So I tried it with negative matches for node, pi, comment and text. > But now the differentiation between namespace node and attribute node > ( for output of xnlns:ns1="..." / xmlns="..." / attr="..." ) > seems a bit complex to me. > > Can this be simplified? > > > <xsl:template match="@*"> > attribute > </xsl:template> > > <xsl:template name="doOutput"> > <xsl:choose> > <!-- attribute could be matched, namespace not - handle both --> > <xsl:when test="not(node()|processing-instruction()|comment()|text > ())"> > <xsl:variable name="isAttribute"> > <xsl:apply-templates select="."/> > </xsl:variable> > <xsl:if test="$isAttribute=''"> > <xsl:text>xmlns</xsl:text> > <xsl:if test="name()">:</xsl:if> > </xsl:if> > <xsl:value-of select="name()"/> > <xsl:text>="</xsl:text> > <xsl:value-of select="string()"/> > <xsl:text>"</xsl:text> > </xsl:when> > <xsl:otherwise> > <xsl:copy-of select="."/> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > > > Mit besten Gruessen / Best wishes, > > Hermann Stamm-Wilbrandt > Developer, XML Compiler, L3 > WebSphere DataPower SOA Appliances > ---------------------------------------------------------------------- > IBM Deutschland Research& Development GmbH > Vorsitzender des Aufsichtsrats: Martin Jetter > Geschaeftsfuehrung: Dirk Wittkopp > Sitz der Gesellschaft: Boeblingen > Registergericht: Amtsgericht Stuttgart, HRB 243294
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Q: XSLT 1.0 output of nam, Michael Kay | Thread | Re: [xsl] Q: XSLT 1.0 output of nam, Lars Huttar |
Re: [xsl] Q: XSLT 1.0 output of nam, Michael Kay | Date | Re: [xsl] Q: XSLT 1.0 output of nam, Lars Huttar |
Month |