xml – XSLT copying without xsl:copy-of – Education Career Blog

I’ve got some *.xml with elements like :

<app-method name="leave-accrual-status-details" kind="enquiry">
    <title>...</title>
    <required-roles>
      <role name="authenticated"/>
    </required-roles>
    <asd>
      <param name="..." datatype="dt:int" control="hidden" call-kind="..." data-kind="..."/>
    </asd>
    <data-engine sp="spLeaveAccrualStatusDetails">
    ...
    </data-engine>
    <wia>
     ...
    </wia>
  </app-method>

And generating new .xml-document (selecting only “app-method” elements).I’m doing it this way : (.xsl)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  <xsl:output method="xml" encoding="utf-8" indent="no"></xsl:output>

  <xsl:template match="/">
  <xsl:for-each select="//app-method">
  <xsl:if test='./required-roles/[email protected]="administrator"'>
  <xsl:copy-of select="." />
  </xsl:if>
  </xsl:for-each>
  </xsl:template>

 </xsl:stylesheet>

It’s working perfectly, but.. Is there any way to do it without “xsl:copy-of”?
Think I need to use something like “node-name(‘blabla’)” and value-of?..
And how to select a set of methods parameters (distinct)? ( param name=”parameter name” ), yeah I need to use “key” but can’t find good samples with it

Many thanks

P.S When converting xml->xml I have to use Far(“xsl in.xml transform.xsl out.xml”),’cause there is some strange error when trying to do it from cdm.exe, I dislike FAR a little bit,is there another way to convert xmls?

,

It’s working perfectly, but.. Is there
any way to do it without
“xsl:copy-of”? Think I need to use
something like “node-name(‘blabla’)”
and value-of?..

Read about the <xsl:element> instruction and also about the identity rule.

.. And how to select a set of methods
parameters (distinct)? ( param
name=”parameter name” ), yeah I need
to use “key” but can’t find good
samples with it

This is a second question (out of three) and very different than the first. Read about Muenchian grouping. And ask it as a separate question.

,

Distinct

    <xsl:key name="pkey" match="param" use="@name"/>

     <xsl:template match="/">
        <xsl:for-each select='//app-method/asd/paramgenerate-id() = generate-id(key("pkey", @name)1)'>
             <parameter>
             <xsl:value-of select="@name"/>
             </parameter>
        </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>

Unique

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>

    <xsl:key name="pkey" match="@name" use="."/>

     <xsl:template match="/">
        <xsl:for-each select="//app-method/asd">
             <xsl:copy-of select='[email protected]() = generate-id(key("pkey",.)1)'/>
        </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>

Using cmd.exe to convert XML :
download MSXSL.exe (newest)
put it in some system folder (that already is included in path variable)
and then from command line
msxsl source.xml transformer.xsl -o result.xml

I’ll Write tomorrow about copying without “copy-of”

BTW : good Tutorial

Leave a Comment