0

I'm new to XSL. Looking here I found the FXSL library that could help solve my problem but I don't know how to go about it.

I have an XML similar to the following one. The application runs an XSL with some external parameters. Within the XML there are some keywords with special meanings:

  • {MY_EXT_PAR} : it refers to an external parameter named MY_EXT_PAR.
  • {1}, {2}, ... : they refer to external parameters named PAR1, PAR2, ...
  • @LINK1(key1), @LINK2(key1,key2) : they are links to a link tag that returns a value (description) related to the given keys. Many links can be defined with a varying number of keys.
  • There should be some keywords to format the text (eg. \n for carriage return).

Sample XML input:

    <Links>
        <Link>
            <Name>LINK1</Name>
            <Element>
                <Key>
                    <Value>1</Value>
                </Key>
                <Description>Description1</Description>
            </Element>
            <Element>
                <Key>
                    <Value>4</Value>
                </Key>
                <Description>Description2</Description>
            </Element>
        </Link>
        <Link>
            <Name>LINK2</Name>
            <Element>
                <Key>
                    <Value>125</Value>
                    <Value>68</Value>
                </Key>
                <Description>Description3</Description>
            </Element>
        </Link>
    </Links>
    <Codes>
        <Code>
            <Description>Connect to external param {MY_EXT_PAR}.\nParameter 1 value is {1} that is @LINK2({2},{3})\n. Parameter 4 value is {4} that is @LINK1({4}).</Description>
        </Code>
    </Codes>

Are there some examples for this?

Emanuele
  • 91
  • 1
  • 2
  • 7
  • Whoever supplies the XML document is not doing you any favors: you have a *lot* of work to do there. Perhaps [this](http://stackoverflow.com/questions/20509618/string-manipulation-using-xslt-tokenize-and-for-each/20510490#20510490) could help to get you started. – michael.hor257k Dec 16 '13 at 12:16
  • BTW, the XML you have posted is not well-formed: the `` element is not closed, and there is no root element. – michael.hor257k Dec 16 '13 at 12:36
  • I know, it's a minor part of real xml. – Emanuele Dec 16 '13 at 12:48
  • I don't see the point of the question. What your xslt must do with that input? – Emiliano Poggi Dec 16 '13 at 13:34
  • In any case, I believe the best solution lies upstream. Presumably this XML is machine-generated. It should be much easier to program the generating machine **not** to place needles in a haystack than to program another machine to pull them out. – michael.hor257k Dec 16 '13 at 13:43
  • 1
    FXSL's good, but I wouldn't recommend using it if you're new to XSL. To be honest, the `{..}` should really be specified using XML elements. Your quickest solution realistically would be to do a blank text-replace, replacing `{` with `` and `}` with ``, and your XSL suddenly becomes 1000 times easier. Your `@LINK` content could probably be replaced with elements relatively easily with a regex replace. – Flynn1179 Dec 16 '13 at 13:55
  • Interesting solution. So I should use MY_EXT_PAR and PAR1, ... Linking seems harder because I should replace @LinkName with variable arguments... – Emanuele Dec 16 '13 at 15:44
  • Well, I'd start with a regex, replacing `@LINK(.+?)\((.*?)\)` with `(capture 2)`, then do a simple text replace, substituting `{` for `` and `}` for ``. That leaves you with your data in a form that's much easier for .XSL to work with. The parameters to your `@LINK` 'functions' will also be converted to ``s, and your xsl can just ignore the commas inbetween. – Flynn1179 Dec 17 '13 at 00:11

0 Answers0