简体   繁体   中英

XSL Transformation with dynamic XML Tags

I have an XML that looks similar to this:

<Element>
    <ele.Name> Name_Value </ele.Name>
    <ele.Age> Age_Value </ele.Age>
    <ele.Something> Something_Value </ele.Something>
<Element>

The Tags themselves are, except for the "ele" part completely dynamic and there can be any number of tags. Meaning there can be 100 different tags, none of them are known beforehand. Only the "ele" part inside the tag.

Now I need to transform the above XML into something like this:

Name;Age;Something
Name_Value;Age_Value;Something_Value

Two Lines, with the tag names in the first line and the values in the second. "ele" must be eliminated from the names. My current problem is that i dont really know how i can access those tags without knowing them beforehand. Maybe someone can give me a hint to find a solution to this problem?

Performance is very relevant here since this might be executed 10000+ times in a single process.

You can process

<xsl:template match="Element">
  <xsl:value-of select="*/substring-after(local-name(), '.')" separator=";"/>
  <xsl:text>&#10;</xsl:text>
  <xsl:value-of select="*" separator=";"/>
</xsl:template>

that assumes XSLT 2 or later. But of course processing * is possible in XSLT 1.0 as well to process all child elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM